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

Not all stream types can be cloexec #4884

Open
headius opened this issue Dec 5, 2017 · 0 comments
Open

Not all stream types can be cloexec #4884

headius opened this issue Dec 5, 2017 · 0 comments

Comments

@headius
Copy link
Member

headius commented Dec 5, 2017

As of JRuby 9.1.15, there are several types of streams that cannot be set close-on-exec:

  1. Java channels that cannot be reflectively unpacked, since we can't get at the file descriptor.
    This means all streams when we can't use native IO (e.g. on Windows currently) and reflection is limited (such as on secured environments or stock Java 9). However my reading of OpenJDK source indicates they are already setting cloexec for most (all?) JDK-provided streams.
    Note that third-party libraries may have their own streams that we do not know how to unwrap.
  2. Streams that have no associated file descriptor, like opaque ReadableChannel or OutputStream wrappers. This is not a large concern because non-fd streams have no fd themselves to cloexec. If they eventually wrap a fd-backed stream, then ideally it's JDK-provided (and so already cloexec) or it handles cloexec itself in some other way.

There are two sides to this feature: whether streams get set cloexec by default, and whether it's possible to change that cloexec bit.

I believe currently all our streams should be getting set to cloexec by default, since the JDK appears to do it for its streams and we are now doing it for our native streams (after fixes to #4858).

As much as possible we should try to support querying cloexec, or a reasonable fallback, for all cases. Currently this is implemented by assuming non-unwrappable streams are already cloexec, since that usually means they're rooted at a JVM stream. For real native streams we can obviously read the cloexec bit.

It will not be possible to change cloexec across all stream types. If we have a stream we can't unwrap and that does not provide a way to change cloexec, we will be unable to change it. The fixes for #4858 include a warning when someone's trying to set cloexec on a stream that can't modify cloexec. We can mitigate some of these cases if native is available; for example, if reflection is disabled but native IO is available we should prefer a native pipe to the JDK-provided pipe (arguably we should always prefer a native pipe for native IO).

At the very least we should have decent documentation and warnings when we're unable to fully support cloexec on a given stream.

@headius headius added this to the JRuby 9.2.0.0 milestone Dec 5, 2017
@enebo enebo modified the milestones: JRuby 9.2.0.0, JRuby 9.2.1.0 May 24, 2018
@headius headius removed this from the JRuby 9.2.1.0 milestone Oct 26, 2018
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

No branches or pull requests

2 participants