https://kotlinlang.org logo
#ktor
Title
# ktor
d

darkmoon_uk

05/30/2021, 8:10 AM
Has anyone successfully deployed a Ktor App that uses WebSockets to a WAR in Jetty Container? While making a simple example Web-App for Compose for Web I encountered this long standing, unresolved issue: • KTOR-184 Ktor tries to use
HttpServletRequest.upgrade()
which is not supported in Jetty ☠️ This appears to be a complete blocker for deploying WebSockets as a WAR in Jetty. Disturbing given that it's a very standard configuration for production usage 😱 Is anyone able to suggest a fix or workaround? Reproduction steps added to ticket.
d

darkmoon_uk

05/31/2021, 1:13 PM
@Chris Miller Thank you. This led me to look further into Jetty versions. The Ktor documentation neglects to mention which Jetty/Netty/Tomcat versions are either embedded or tested against - this is surely a gap, given the variation in compatibility across versions that I'm uncovering. My original error was seen when hosting a basic websocket-example 'Ktor WAR' in a Jetty instance provided by the
docker:latest
container. It transpires that
latest
is Jetty version
9.x
- while
10.x
and
11.x
version streams also exist. I tested these: •
9.x
, as already seen, doesn't implement the connection
upgrade()
method that Ktor calls internally from its WebSocket implementation. •
11.x
is plainly unsuitable - it represents Jetty project's 'big bang' move to a new Jakarta project servlet standard and doesn't recognise the
javax.*
family of Servlet classes at all. • That leaves
10.x
- I hoped this would work but instead I get a new error from the Server when it attempts to open the WebSocket session:
ERROR Application - 101 Switching Protocols: GET - /web-getting-started-webapp/numberUpdates java.lang.IllegalStateException: s=WAITING rs=ASYNC os=OPEN is=IDLE awp=false se=false i=false al=0
👍 1
@e5l As I can see you are the major author of WebSockets feature in Ktor, wondering if you can kindly shine any light on this Jetty/WAR deployment situation? Maybe there's some 'gotcha' I'm missing.
e

e5l

05/31/2021, 2:27 PM
Hey, sure. Will take a look
d

darkmoon_uk

06/01/2021, 9:51 AM
Hi @e5l, I understand there may be higher priorities, but do you have any more thoughts on using WebSockets from a WAR? I'll try to create an even more minimal example tonight (next few hours here in Aus) and will update the ticket with any findings.
I'm working with Ktor code snippets from the documentation repo. Notes re: the
jetty-war
sample: • There's nothing about it that looks Jetty specific - could/should be called
servlet-war
? • The Gretty plugin version referenced is unmaintained, and should be updated to
org.gretty
,
3.0.4
• The sample doesn't work because the main module referenced in
application.conf
isn't fully qualified. Changing it to
io.ktor.snippets.hello.HelloApplicationKt.main
makes it work. I'll probably raise a PR with these fixes soon.
Confirmed that even minimally adding
install(WebSockets)
and
webSocket("/ws") { send(Frame.Text("Hello")) }
to the lightly fixed
jetty-war
sample, gives rise to:
Copy code
2021-06-01 14:43:41.914 [pool-20-thread-3] ERROR Application - 101 Switching Protocols: GET - /jetty-war/ws
java.lang.IllegalStateException: s=WAITING rs=ASYNC os=OPEN is=IDLE awp=false se=false i=false al=0
...
...when the
war
is deployed in my Dockerised Jetty 10.x Container instance.
In this case the Ktor version is
1.6.0
, so WS still broken there 😞
4 Views