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

Support CIO server for wasm-js and js #4466

Open
wants to merge 8 commits into
base: 3.1.0-eap
Choose a base branch
from

Conversation

whyoleg
Copy link
Contributor

@whyoleg whyoleg commented Nov 8, 2024

Subsystem
Server CIO

Motivation
Probably fixes https://youtrack.jetbrains.com/issue/KTOR-865/Add-node.js-server-engine, though not sure, may be more specific issue should be created

Solution
Most of the code in ktor-server-cio is just copied with minor changes.

P.S. This is the last PR in a series of ktor server support for wasm-js and js! wasm-wasi will be next, probably, if I will be able to find working runtime which supports preview1 socket APIs...

@osipxd osipxd self-requested a review November 8, 2024 17:41
@osipxd
Copy link
Member

osipxd commented Nov 13, 2024

Relates to:

  • KTOR-2939 ApplicationEngine.start()/stop() should be suspending
  • KTOR-7459 Implement a suspending version of EmbeddedServer.start(wait=true)

Copy link
Member

@osipxd osipxd left a comment

Choose a reason for hiding this comment

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

This is the last PR in a series of ktor server support for wasm-js and js!

Thank you, it's a huge work 🎉

Please, check JVM builds on CI, they fail after two hours with timeout because of hanging NettyHttp2ServerCommonTest.

@@ -179,6 +179,8 @@ public abstract class BaseApplicationResponse(
}
} catch (closed: ClosedWriteChannelException) {
throw ChannelWriteException(exception = closed)
} finally {
flushAndClose()
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to call flushAndClose inside .use { } block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH, I'm not fully sure if this fixes the original issue (some tests failure), so I will revert this change...
The idea behind this change is that use on ByteWriteChannel is custom and uses close which in reality calls flushAndClose, but doesn't wait for it completion.
so use{} and flushAndClose are mostly the same, except for the fact that flushAndClose really suspends

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted in 9bbd0d3

Now JVM tests are working fine, looks like this was the reason, as this is the only change which affects JVM.
But now testErrorInBodyClosesConnection started to fail again - it shows it as flaky, so may be it's really related to this fireAndForget close method in channels

Copy link
Member

@osipxd osipxd Nov 14, 2024

Choose a reason for hiding this comment

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

@e5l, could you take a look? Should we call flushAndClose instead of deprecated close inside of use?

Copy link
Member

Choose a reason for hiding this comment

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

The difference is in the exception: flushAndClose can throw if the flush is failed. Could you check if this is the case?

@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 13, 2024

@osipxd should I create an additional issue for this, or https://youtrack.jetbrains.com/issue/KTOR-865/Add-node.js-server-engine will be fine?

Relates to:

  • KTOR-2939 ApplicationEngine.start()/stop() should be suspending
  • KTOR-7459 Implement a suspending version of EmbeddedServer.start(wait=true)

Do you think it will be better to extract those changes and create a separate PR for them? If so, I will do it :)

@osipxd
Copy link
Member

osipxd commented Nov 14, 2024

Should I create an additional issue for this, or https://youtrack.jetbrains.com/issue/KTOR-865/Add-node.js-server-engine will be fine?

@e5l, was this task created for some new Node.js engine or CIO fits the purpose?

Relates to:

  • KTOR-2939 ApplicationEngine.start()/stop() should be suspending
  • KTOR-7459 Implement a suspending version of EmbeddedServer.start(wait=true)

Do you think it will be better to extract those changes and create a separate PR for them? If so, I will do it :)

Yes, it would be great to discuss this separately. Probably we should deprecate the existing start/stop implementation and at some point and gradually migrate to the suspend version.

@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 14, 2024

Yes, it would be great to discuss this separately.

Extracted to #4481

@e5l
Copy link
Member

e5l commented Nov 20, 2024

I think we can adjust the issue to include wasm

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

Successfully merging this pull request may close these issues.

3 participants