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

Quarkus Websockets Next client connector is not reusable #44465

Closed
andreiyusupau opened this issue Nov 13, 2024 · 4 comments
Closed

Quarkus Websockets Next client connector is not reusable #44465

andreiyusupau opened this issue Nov 13, 2024 · 4 comments
Labels
area/websockets env/windows Impacts Windows machines kind/bug Something isn't working

Comments

@andreiyusupau
Copy link

Describe the bug

I'm trying to open multiple connections using Websockets Next. Connections require different headers for auth purposes. Due to addHeader method not overwriting headers, but just adding new ones to the list, my upgrade request sends the initial header value instead of the new one.
How could the connector be reused?

Expected behavior

connector should be completely reusable

Actual behavior

connector is not reusable

How to Reproduce?

    @Inject
    WebSocketConnector<ExampleWebsocketClient> connector;

  public void connect() {
            var connection1 = connector.baseUri(uri)
                    .addHeader("Custom-Header", 1)
                    .connectAndAwait();

            var connection2 = connector.baseUri(uri)
                    .addHeader("Custom-Header", 2)
                    .connectAndAwait(); // still sends "Custom-Header"=1
}

Output of uname -a or ver

Microsoft Windows [Version 10.0.22631.4317]

Output of java -version

Amazon Coretto 21

Quarkus version or git rev

3.16.2

Build tool (ie. output of mvnw --version or gradlew --version)

gradle 8.10.2

Additional information

No response

@andreiyusupau andreiyusupau added the kind/bug Something isn't working label Nov 13, 2024
@quarkus-bot quarkus-bot bot added env/windows Impacts Windows machines triage/needs-triage labels Nov 13, 2024
@geoand
Copy link
Contributor

geoand commented Nov 13, 2024

cc @mkouba

@mkouba
Copy link
Contributor

mkouba commented Nov 13, 2024

An injected WebSocketConnector should not be reused. It was not designed that way. I will update the javadoc which currently only states "This construct is not thread-safe and should not be used concurrently".

You can inject jakarta.enterprise.inject.Instance<WebSocketConnector<ExampleWebsocketClient>> connector instead, and then call connector.get() to obtain a new instance of WebSocketConnector.

@andreiyusupau
Copy link
Author

@mkouba Thanks, works nice

mkouba added a commit to mkouba/quarkus that referenced this issue Nov 13, 2024
- also add tests for programmatic lookup of connectors
- related to quarkusio#44465
@mkouba
Copy link
Contributor

mkouba commented Nov 13, 2024

@mkouba Thanks, works nice

I've tried to improve the javadoc/docs in #44467 so that it's more clear.

bschuhmann pushed a commit to bschuhmann/quarkus that referenced this issue Nov 16, 2024
- also add tests for programmatic lookup of connectors
- related to quarkusio#44465
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 19, 2024
- also add tests for programmatic lookup of connectors
- related to quarkusio#44465

(cherry picked from commit c59a6dc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/websockets env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants