Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autoUnref option to Manager #1446

Closed
KCErb opened this issue Feb 22, 2021 · 1 comment
Closed

add autoUnref option to Manager #1446

KCErb opened this issue Feb 22, 2021 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@KCErb
Copy link

KCErb commented Feb 22, 2021

I'm opening this issue to discuss a PR I put up a couple of weeks ago. Perhaps some community discussion is more appropriate/likely here than there?

Is your feature request related to a problem? Please describe.

If a client app is trying to reconnect, it leaves a refd timer on the event loop which will prevent the program from exiting. This might be desirable behavior but it'd be nice to be able to turn it off.

Describe the solution you'd like

The timer API already supports the notion of unref for exactly this purpose: https://node.readthedocs.io/en/latest/api/timers/#unref. And I ran into a similar issue in the underlying engine so the two could share the same option: socketio/engine.io-client#652.

Describe alternatives you've considered
One alternative I've considered came from this stackoverflow thread: https://stackoverflow.com/questions/62028744/can-socket-io-clients-be-setup-to-not-keep-nodejs-from-exiting to spawn a child. It's a bit awkward having to serialize and pass info from the child back to the parent via IPC though just to deal with socket.io internals preventing the event loop from exiting.

Of course, the other alternative is to just use the close method, but I'm trying to handle gracefully the case where the user calling my library fails to call close on my wrapper and is scratching their head as to why their program is hung.

Additional context
#1442

@KCErb KCErb added the enhancement New feature or request label Feb 22, 2021
darrachequesne pushed a commit that referenced this issue Mar 10, 2021
With autoUnref set to true (default: false), the Socket.IO client will
allow the program to exit if there is no other active timer/socket in
the event system.

```js
const socket = io({
  autoUnref: true
});
```

Note: this option only applies to Node.js clients.

Related: #1446
@darrachequesne
Copy link
Member

Implemented in 6abfa1f and included in [email protected]. Thanks!

@darrachequesne darrachequesne added this to the 4.0.0 milestone Mar 12, 2021
sunrise30 added a commit to sunrise30/socket.io-client that referenced this issue Jan 8, 2022
With autoUnref set to true (default: false), the Socket.IO client will
allow the program to exit if there is no other active timer/socket in
the event system.

```js
const socket = io({
  autoUnref: true
});
```

Note: this option only applies to Node.js clients.

Related: socketio/socket.io-client#1446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants