diff --git a/lib/transport.js b/lib/transport.js index de5bb14..ca71569 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -63,10 +63,18 @@ const createUdpTransport = args => { } dnsResolutionData.resolvedAddress = address; dnsResolutionData.timestamp = now; - socket.send(buf, 0, buf.length, args.port, dnsResolutionData.resolvedAddress, callback); + try { + socket.send(buf, 0, buf.length, args.port, dnsResolutionData.resolvedAddress, callback); + } catch (socketError) { + callback(socketError); + } }); } else { - socket.send(buf, 0, buf.length, args.port, dnsResolutionData.resolvedAddress, callback); + try { + socket.send(buf, 0, buf.length, args.port, dnsResolutionData.resolvedAddress, callback); + } catch (socketError) { + callback(socketError); + } } }; @@ -78,7 +86,11 @@ const createUdpTransport = args => { if (args.cacheDns) { sendUsingDnsCache(callback, buf); } else { - socket.send(buf, 0, buf.length, args.port, args.host, callback); + try { + socket.send(buf, 0, buf.length, args.port, args.host, callback); + } catch (socketError) { + callback(socketError); + } } }, close: socket.close.bind(socket),