Skip to content

Fixing DNS empty crash and unsafe socket error#16

Merged
kasperisager merged 4 commits intoholepunchto:mainfrom
shaikh-shahid:main
Feb 19, 2026
Merged

Fixing DNS empty crash and unsafe socket error#16
kasperisager merged 4 commits intoholepunchto:mainfrom
shaikh-shahid:main

Conversation

@shaikh-shahid
Copy link
Contributor

1: Fixing the DNS empty crash

  • In Socket.connect(), DNS callback now handles err, non-array results, and empty address arrays safely.
  • If lookup returns no addresses, it now creates an ENOTFOUND error and follows the normal open/destroy flow instead of destructuring an empty array.

2: Removing unsafe throw in async server connection
Replaced throw err with this.emit('error', err) after socket.destroy() to avoid process crash

3: Fix native writev buffer lifetime

  • Keep uv_buf_t allocations alive until uv_write completion callback.
  • Added cleanup for success, close-path fallback, and sync-failure paths.

Ran npm test and 17/17 tests passing, 54/54 assertions passing.

TAP version 13

# server + client
    ok 1 - (lifecycle) - server listening
    ok 2 - (lifecycle) - client connection opened
    ok 3 - (lifecycle) - server received message
    ok 4 - (lifecycle) - client connection closed
    ok 5 - (lifecycle) - server connection closed
    ok 6 - server closed
ok 1 - server + client # time = 4ms

# connect IPv4 loopback
    ok 1 - (lifecycle) - server listening
    ok 2 - (lifecycle) - client connection opened
    ok 3 - (lifecycle) - server received message
    ok 4 - (lifecycle) - client connection closed
    ok 5 - (lifecycle) - server connection closed
    ok 6 - server closed
ok 2 - connect IPv4 loopback # time = 1ms

# socket state getters
    ok 1 - pending
    ok 2 - connecting
ok 3 - socket state getters # time = 0ms

# address getters
    ok 1 - should be equal
    ok 2 - should be equal
    ok 3 - should be equal
    ok 4 - should be equal
    ok 5 - should be equal
    ok 6 - should be equal
    ok 7 - expected truthy value
    ok 8 - should be equal
    ok 9 - should be equal
    ok 10 - should be equal
    ok 11 - should be equal
    ok 12 - should be equal
    ok 13 - should be equal
    ok 14 - expected truthy value
ok 4 - address getters # time = 1ms

# port already in use
    ok 1 - catch EADDRINUSE error
ok 5 - port already in use # time = 1ms

# port already in use, listen again
    ok 1 - catch EADDRINUSE error
    ok 2 - passed
ok 6 - port already in use, listen again # time = 1ms

# not accept address request when not listening
    ok 1 - should be equal
ok 7 - not accept address request when not listening # time = 0ms

# not accept server calling listen method twice
    ok 1 - should be equal
ok 8 - not accept server calling listen method twice # time = 1ms

# createConnection and connect arguments
    ok 1 - (createConnection) - port, host and listener
    ok 2 - (createConnection) - port and listener
    ok 3 - (createConnection) - options and listener
    ok 4 - (connect) - port and listener
    ok 5 - (connect) - port, host and listener
    ok 6 - (connect) - options and listener
ok 9 - createConnection and connect arguments # time = 1ms

# server.listen arguments
    ok 1 - (args) - port, host and listener
    ok 2 - (args) - no args
    ok 3 - (args) - listener
    ok 4 - (args) - port and listener
ok 10 - server.listen arguments # time = 1ms

# ipv6 support
    ok 1 - server family is 'IPv6'
    ok 2 - received message
ok 11 - ipv6 support # time = 1ms

# handle invalid host
    ok 1 - expected truthy value
ok 12 - handle invalid host # time = 3ms

# basic timeout
    ok 1 - should be equal
    ok 2 - timeout callback
    ok 3 - timeout event
ok 13 - basic timeout # time = 102ms

# disable timeout with setTimeout(0)
    ok 1 - should be equal
    ok 2 - timeout not triggeded
ok 14 - disable timeout with setTimeout(0) # time = 203ms

# timeout option
    ok 1 - timeout triggered
ok 15 - timeout option # time = 102ms

# should not trigger timeout by writing activity
    ok 1 - timeout not triggered
ok 16 - should not trigger timeout by writing activity # time = 502ms

# should not trigger timeout by reading activity
    ok 1 - timeout not triggered
ok 17 - should not trigger timeout by reading activity # time = 502ms

1..17
# tests = 17/17 pass
# asserts = 54/54 pass
# time = 1426ms

# ok

Copy link
Contributor

@kasperisager kasperisager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@shaikh-shahid
Copy link
Contributor Author

Updated the PR with your comments.

Copy link
Contributor

@kasperisager kasperisager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks so much! I'll merge and publish when the workflows pass.

@kasperisager kasperisager merged commit 19fc976 into holepunchto:main Feb 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants