Skip to content

IXWebSocket client creates a lot of threads when connecting to some urls #406

Closed as not planned

Description

@Ringflash

After start() method IXWebSocket creates around 30 threads when connecting to some urls. wss is using.
One of that threads is using to send messages, one for receiving.
How can I force IXWebSocket to use only one thread (like for other urls)?
Compiled with "cmake -DUSE_TLS=1 -DUSE_ZLIB=1 -DUSE_OPEN_SSL=1 .."
Attached screenshots
screen 2
screen 1
.

Activity

  1. bsergean commented on Aug 2, 2022

    @bsergean
    Collaborator

    I don't know what goes wrong with this remote url. Can you connect to it with anothe library ? Maybe it has some SSL problem ?

    You could also try an older version of ixwebsocket.

  2. bsergean commented on Aug 2, 2022

    @bsergean
    Collaborator

    Can you connect to it with the connect ws sub-command ?

  3. Ringflash commented on Aug 3, 2022

    @Ringflash
    Author

    I don't know what goes wrong with this remote url. Can you connect to it with anothe library ? Maybe it has some SSL problem ?

    I've tried with another ws library and it doesn't create additional threads for that url.

    You could also try an older version of ixwebsocket.

    I've tried v11.0.8 and v10.4.0. Same result. A lot of threads.

  4. Ringflash commented on Aug 3, 2022

    @Ringflash
    Author

    Can you connect to it with the connect ws sub-command ?

    I don't get how to do it. What method should I use?

  5. bsergean commented on Aug 3, 2022

    @bsergean
    Collaborator

    ws is a command line interface. Build ws like this:

    mkdir -p build && (cd build ; cmake -DCMAKE_UNITY_BUILD=OFF -DUSE_TEST=OFF -DUSE_TLS=ON -DUSE_WS=ON .. ; make -j8)
    

    Then:

    $ ./build/ws/ws connect --help
    Connect to a remote server
    Usage: ./build/ws/ws connect [OPTIONS] url
    
    Positionals:
      url TEXT REQUIRED           Connection url
    
    Options:
      -h,--help                   Print this help message and exit
      -H TEXT                     Header
      -d                          Disable Automatic Reconnection
      -x                          Disable per message deflate
      -b                          Send in binary mode
      --max_wait UINT             Max Wait Time between reconnection retries
      --ping_interval INT         Interval between sending pings
      --subprotocol TEXT          Subprotocol
      -g                          Decompress gziped messages
      --pidfile TEXT              Pid file
      --cert-file TEXT:PATH(existing)
                                  Path to the (PEM format) TLS cert file
      --key-file TEXT:PATH(existing)
                                  Path to the (PEM format) TLS key file
      --ca-file TEXT:PATH(existing)
                                  Path to the (PEM format) ca roots file
      --ciphers TEXT              A (comma/space/colon) separated list of ciphers to use for TLS
      --tls                       Enable TLS (server only)
      --verify_none               Disable peer cert verification
    
  6. bsergean commented on Aug 3, 2022

    @bsergean
    Collaborator

    I tried this remote websocket test server -> https://www.piesocket.com/websocket-tester

    ./build/ws/ws connect 'wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self'
    Type Ctrl-D to exit prompt...
    Connecting to url: wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self
    > [2022-08-03 09:18:15.955] [info] ws_connect: connected
    [2022-08-03 09:18:15.955] [info] Uri: /v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self
    [2022-08-03 09:18:15.955] [info] Headers:
    [2022-08-03 09:18:15.955] [info] Connection: upgrade
    [2022-08-03 09:18:15.955] [info] Date: Wed, 03 Aug 2022 16:18:15 GMT
    [2022-08-03 09:18:15.955] [info] Sec-WebSocket-Accept: Q0GhXhe+4qTaAWniof2ye1PPPjI=
    [2022-08-03 09:18:15.955] [info] sec-websocket-extensions: 
    [2022-08-03 09:18:15.955] [info] Upgrade: websocket
    [2022-08-03 09:18:15.955] [info] X-Powered-By: Ratchet/0.4.4
    [2022-08-03 09:18:15.990] [info] Received pong ixwebsocket::heartbeat::30s::0
    [2022-08-03 09:18:18.664] [info] Received 12 bytes
    ws_connect: received message: Hello world!
    [2022-08-03 09:18:18.665] [info] Received 12 bytes
    ws_connect: received message: Hello world!
    [2022-08-03 09:18:18.665] [info] Received 12 bytes
    ws_connect: received message: Hello world!
    [2022-08-03 09:18:18.665] [info] Received 12 bytes
    ws_connect: received message: Hello world!
    [2022-08-03 09:18:18.782] [info] Received ping
    
    [2022-08-03 09:18:21.879] [info] 
    ws_connect: connection closed: code 1000 reason Normal closure
    
    ws_connect: stop connection completed in 38222 us
    [2022-08-03 09:18:21.918] [info] Received 91 bytes
    [2022-08-03 09:18:21.918] [info] Sent 0 bytes
    
  7. bsergean commented on Aug 4, 2022

    @bsergean
    Collaborator
    1. What OS are you using ?
    2. Is the URL public, can you share it ?
  8. Ringflash commented on Aug 4, 2022

    @Ringflash
    Author

    Can you connect to it with the connect ws sub-command ?

    Connected and no problems. Two threads for ws process.

    1. What OS are you using ?

    Ubuntu 20.04. App compiled with g++-11

    2. Is the URL public, can you share it ?
    

    It is public, but I've sent it to your email. And some messages to test with.

    It seems that new threads are created not after connection to url but after sending some messages.

  9. nini2009ph commented on Sep 4, 2022

    @nini2009ph

    try adding webSocket.disableAutomaticReconnection();

  10. Ringflash commented on Sep 17, 2022

    @Ringflash
    Author

    try adding webSocket.disableAutomaticReconnection();

    Same thing. Didn't help

  11. bsergean commented on Nov 17, 2026

    @bsergean
    Collaborator

    I revisited this report against the current threading model. start() owns one connection thread; hostname resolution can temporarily use a resolver worker. Sending/receiving messages does not itself create additional IXWebSocket worker threads. #656 removes the resolver worker entirely for numeric addresses and fixes detached-worker ownership, but that does not establish the cause of this application's post-message thread growth.

    The CLI connecting to the same endpoint was reported to work normally earlier in this discussion. Could you provide a minimal current application that reproduces the growth after a message, plus stack traces of the newly created threads? Those stacks are needed to distinguish connection/resolver work from callbacks, application code or TLS-provider threads. See the current threading documentation.

  12. bsergean commented on Nov 17, 2026

    @bsergean
    Collaborator

    Closing this old report because we do not have a current application reproduction or thread stacks, and the reporter confirmed that the CLI did not show the problem with the same endpoint. We cannot attribute the application thread growth to IXWebSocket from the available evidence. Please reopen with a minimal current reproduction and stacks of the extra threads if it still occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions