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

NIOCore/NIOLoopBound.swift:120: Precondition failed in 2.14.0 #140

Open
jhoughjr opened this issue Jun 14, 2023 · 7 comments
Open

NIOCore/NIOLoopBound.swift:120: Precondition failed in 2.14.0 #140

jhoughjr opened this issue Jun 14, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@jhoughjr
Copy link
Collaborator

jhoughjr commented Jun 14, 2023

Describe the bug

I'm seeing a precondition failed when setting onText or onBinary on an upgraded websocket.

To Reproduce

vapor new testing; cd testing; open Package.swift;

add the following route to routes.swift

  app.webSocket("test",
                  maxFrameSize: WebSocketMaxFrameSize.default) { req in
        return req.headers
        
    } onUpgrade: { req, webSoc in
        
        webSoc.onText { ws, text in
            app.logger.info("\(text)")
        }
    }

Build and run. Then connect to ws://localhost:8080/test with a websocket client.
When the onText handler is added, the server will crash with precondition failed.

Expected behavior

A properly added onText or onBinary handler that does not fail the box's precondition and crash.

Environment

MacOS 13.4, m1 Mac mini 2020
Xcode 14.3.1
Vapor: 4.77.0
toolbox: 18.7.1
websocket-kit: 2.14.0

Additional context

Add any other context about the problem here.

[ INFO ] GET /test [request-id: 1E6A83B5-84A4-4234-B5B2-B705F9F8C8BB]
NIOCore/NIOLoopBound.swift:120: Precondition failed
2023-06-14 08:23:57.758835-0500 App[44596:2119282] NIOCore/NIOLoopBound.swift:120: Precondition failed```
@jhoughjr jhoughjr added the bug Something isn't working label Jun 14, 2023
@abidon
Copy link

abidon commented Jul 30, 2023

I have the same bug. Is there a fix in the pipeline or a workaround ?

@vasek-broz
Copy link

I am getting into almost the same trouble. Only the backtrace points to a different file and line in NIOCore. It happens on localhost during development as well as on Heroku where I host the application. I have also found out that ti started happening from version 2.13.0 so I am for now staying with 2.12.1 specified in package manifest.

@m-barthelemy
Copy link

Same here using websocket-kit as a client.

@florianpeninon
Copy link

Facing the same bug. Any update on a fix/workaround?

@mjKosmic
Copy link

i had the same issue when i was accidentally mixing escaping closure syntax and async/await in my websocket routes. fixing that fixed the problem for me

@0xTim
Copy link
Member

0xTim commented Nov 1, 2023

You should be able to wrap your onText etc calls inside an event loop submit or similar to remove. But we are working on this and trying to fix the underlying issue

@laugonz
Copy link

laugonz commented Apr 10, 2024

i had the same issue when i was accidentally mixing escaping closure syntax and async/await in my websocket routes. fixing that fixed the problem for me

Hey, thanks a ton! Your tip about not mixing up escaping closures with async/await was spot-on. I wrapped my async/await stuff in a Task { ... }, and this fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants