Skip to content

fix: resolve allowHalfOpen behavior and refactor NativeModules usage#230

Merged
Rapsssito merged 2 commits intoRapsssito:masterfrom
akai07:fix/allow-half-open
Jan 16, 2026
Merged

fix: resolve allowHalfOpen behavior and refactor NativeModules usage#230
Rapsssito merged 2 commits intoRapsssito:masterfrom
akai07:fix/allow-half-open

Conversation

@akai07
Copy link
Contributor

@akai07 akai07 commented Jan 15, 2026

Summary

This PR fixes a critical issue where allowHalfOpen: false (default) failed to trigger the socket end sequence correctly, causing UnexpectedEOFError in relay dialing scenarios. It also refactors the Socket.js module to use NativeModules.TcpSockets directly, eliminating potential variable scoping issues during testing.

Changes

  • Fixed allowHalfOpen Logic: Modified the end event listener in src/Socket.js. When allowHalfOpen is false, this.end() is now called before emitting the 'end' event to consumers. This ensures the FIN packet is sent immediately, matching Node.js net behavior.
  • Refactored NativeModules: Removed the file-level const Sockets declaration and replaced all usages with direct NativeModules.TcpSockets calls. This prevents stale closure captures in test environments where mocks may be reset.

Verification

  • Test: npm test __tests__/allowHalfOpen.test.js
  • Result: All tests passed (previously failing on expect(Sockets.end).toHaveBeenCalled()).

Related Issues

Fixes relay dialing UnexpectedEOFError.

@Rapsssito
Copy link
Owner

Rapsssito commented Jan 15, 2026

Hi @akai07,

Thanks for the PR! Could you please fix the lint and type issues regarding Jest? As soon as you fix those, I will merge the PR.

@akai07 akai07 force-pushed the fix/allow-half-open branch from ced7971 to bfcd1c5 Compare January 15, 2026 20:43
@Rapsssito Rapsssito merged commit dafe6f4 into Rapsssito:master Jan 16, 2026
1 check passed
github-actions bot pushed a commit that referenced this pull request Jan 16, 2026
## [6.4.1](v6.4.0...v6.4.1) (2026-01-16)

### Bug Fixes

* resolve allowHalfOpen behavior ([#230](#230)) ([dafe6f4](dafe6f4))
@github-actions
Copy link

🎉 This PR is included in version 6.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants