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?

Copy link
Contributor Author

@whyoleg whyoleg Nov 22, 2024

Choose a reason for hiding this comment

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

Do you think may be it will be better to create a separate issue for this to investigate? :)

I see, that the same test fails sometimes (flaky) not only for js/wasm-js. And as I reverted this change, it should not affect anything.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's move this investigation into a separate task

@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

@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 22, 2024

Hey @osipxd I've rebased PR on latest changes (e.g EmbeddedServer.startSuspend). Do you think there is something else needed from me here?

I saw, that there is some progress to improve tests stability, but those changes are only in main currently. Are you planning to merge them into 3.1.0-eap anytime soon?

@whyoleg whyoleg requested a review from osipxd November 22, 2024 09:02
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.

Thank you! LGTM

As we decided to move investigation of the flaky test to a separate task, it would be great to ignore this test. However, I don't think it is possible to ignore a test only on one platform. I thought about adding annotations like @JsIgnore, @JvmIgnore, etc., but it feels out of the task scope. I think we'll merge tests stabilizing changes today, so we'll check if it helps.

@osipxd
Copy link
Member

osipxd commented Nov 26, 2024

Hey @whyoleg, we've merged commits fixing tests flakiness to 3.1.0-eap branch. Could you rebase this PR one more time?

@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 26, 2024

Sure, @osipxd, rebased!

@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 26, 2024

@osipxd: TC builds failed because of Canceled by Osip Fatkullin: Wrong agent requirements - is it something expected ? :)

@osipxd
Copy link
Member

osipxd commented Nov 26, 2024

is it something expected ? :)

Yes, it was because of me broken CI exactly at that moment. Should be fixed now. Restarted the build chain

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