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

Remove not on eventLoop precondition for NIOPipeBootstrap #1977

Merged
merged 4 commits into from
Oct 18, 2021

Conversation

jabwd
Copy link
Contributor

@jabwd jabwd commented Oct 15, 2021

Remove not on eventLoop precondition for NIOPipeBootstrap

Motivation:

Currently you cannot create a NIOPipeBootstrap when you are on
an event loop due to a precondition check. This check seeks to prevent
consumers of the API from passing in a file descriptor thats referencing
a file on disk or on the network.
fstat could potentially block the current event loop especially if the file descriptor is referencing a file over the network.
This check however prevents certain use cases of SwiftNIO, where the downsides
of a consumer of this api blocking their own event loop do not weigh in against preventing
an entire use case from SwiftNIO.

Modifications:

Removed the precondition

Result:

After this change it will be possible to feed file descriptors into the bootstrap which potentially block the current event loop.
A potential (portable) replacement for fstat still has to be found in order to solve this problem completely.

Motivation:

Currently you cannot create a NIOPipeBootstrap when you are on
an event loop due to a precondition check. This check seeks to prevent
consumers of the API from passing in a file descriptor thats referencing
a file on disk or on the network.

The method at hand 'validateFileDescriptorIsNotAFile' uses fstat, which potentially
could block the event loop especially if the fd is referencing a file over the network.
This check however prevents certain use cases of SwiftNIO, where the downsides
of a consumer of this api blocking their own event loop do not weigh in against preventing
an entire use case from SwiftNIO.

Modifications:

Removed the precondition

Result:

After this change it will be possible to feed file descriptors into
the bootstrap which potentially block the current event loop.
A potential (portable) replacement for fstat still has to be found in order to solve this problem completely.
@swift-server-bot
Copy link

Can one of the admins verify this patch?

11 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa Lukasa added the semver/patch No public API change. label Oct 15, 2021
@Lukasa
Copy link
Contributor

Lukasa commented Oct 15, 2021

@swift-nio-bot test this please

@Lukasa
Copy link
Contributor

Lukasa commented Oct 15, 2021

@jabwd Thanks for this patch! Ideally we'd write a test for this to confirm that it works: can you replicate a simple one of the NIOPipeChannel tests and run the bootstrap from inside an eventLoop.execute block?

@jabwd
Copy link
Contributor Author

jabwd commented Oct 15, 2021

@Lukasa I created a simple test; I'm not super sure if the failure modes are acceptable however. If I reintroduce the precondition It'll essentially crash the test rather than just count as a fail.

@jabwd jabwd force-pushed the remove-pipebootstrap-precondition branch from 5e24227 to 2ccfdb7 Compare October 15, 2021 19:28
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

I think this is a totally fine test: we don't need really sophisticated failure modes for it because, as you say, we currently crash if you try to do it. This test exists mostly so we know that this should work.

@Lukasa
Copy link
Contributor

Lukasa commented Oct 18, 2021

@swift-nio-bot test this please

@Lukasa
Copy link
Contributor

Lukasa commented Oct 18, 2021

Do you mind running ./scripts/generate_linux_tests.rb and committing the resulting changes?

@jabwd
Copy link
Contributor Author

jabwd commented Oct 18, 2021

My bad, forgot about running that! Changes have been pushed 👍

@Lukasa
Copy link
Contributor

Lukasa commented Oct 18, 2021

@swift-nio-bot test this please

@Lukasa Lukasa merged commit 787e228 into apple:main Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants