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

selectors API encourages signal file descriptor leak #12354

Open
disruptek opened this issue Oct 3, 2019 · 8 comments
Open

selectors API encourages signal file descriptor leak #12354

disruptek opened this issue Oct 3, 2019 · 8 comments

Comments

@disruptek
Copy link
Contributor

I made a selector like this:

type
	Monitor = enum
		Output = "the process has some data for us on stdout"
		Errors = "the process has some data for us on stderr"
		Finished = "the process has finished"

var
	process = startProcess("/some/long/process/with/output", [])
	watcher = newSelector[Monitor]()

watcher.registerProcess(process.processId, Finished)

# ... some things happened ...

watcher.close

This is leaking the file descriptor returned by registerProcess.

one solution

I would like close to unregister any extant event listeners.

another solution

A lesser solution might be to make registerProcess not be {.discardable.}.

Thanks to @zevv for help debugging.

Nim Compiler Version 1.0.99 [Linux: amd64]
Compiled at 2019-10-03
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: c51857f4348823f647110e8a1ede07d76d93b7da
active boot switches: -d:danger
@dom96
Copy link
Contributor

dom96 commented Oct 3, 2019

A lesser solution might be to make registerProcess not be {.discardable.}.

That is the solution, of course now it'll break code... So silly that registerProcess is discardable.

So the next best solution is to make the close for Selector throw an error when it has some file descriptors that haven't been closed. But... that also has the potential to break code...

I think we're left with only one option: deprecate registerProcess and introduce a new proc that isn't discardable.

@zevv
Copy link
Contributor

zevv commented Oct 3, 2019

dom96, what is wrong with making close() cleanup any un-unregistered resources?

@dom96
Copy link
Contributor

dom96 commented Oct 3, 2019

One problem I can think of is: what if you have two selectors and register the same FDs into both?

@disruptek
Copy link
Contributor Author

Why would that be a problem?

@dom96
Copy link
Contributor

dom96 commented Oct 19, 2019

because closing one of the selectors will close FDs that belong to another selector

@disruptek
Copy link
Contributor Author

Nah.

@dom96 dom96 reopened this Oct 20, 2019
@dom96
Copy link
Contributor

dom96 commented Oct 20, 2019

As discussed on IRC, this is a problem and I think we should solve this by deprecating registerProcess and introducing a non-discardable version of it with a new name.

@disruptek
Copy link
Contributor Author

Appears to be an identical problem with registerTimer...

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

No branches or pull requests

3 participants