websocket icon indicating copy to clipboard operation
websocket copied to clipboard

Multiple open connections when subscription changes quickly

Open Keyamoon opened this issue 8 years ago • 1 comments

To reproduce this issue, try the SSCCE that follows and double click on the Toggle button a couple of times. You should see multiple open/pending connections in Chrome's Network tab. If you allow some delay between clicks, connections get closed properly.

I have tried this on macOS version 10.12.5 using Chrome version 58.0.3029.110 and Chrome Canary version 61.0.3132.0.

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import WebSocket


main =
  Html.program
    { init = init
    , view = view
    , update = update
    , subscriptions = subscriptions
    }


echoServer : String
echoServer =
  "wss://echo.websocket.org"


type alias Model = Bool


init : (Model, Cmd Msg)
init =
  (True, Cmd.none)


type Msg
  = NewMessage String
  | Toggle


update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    Toggle ->
      (not model, Cmd.none)
    _ ->
      (model, Cmd.none)


subscriptions : Model -> Sub Msg
subscriptions model =
  if model
     then WebSocket.listen echoServer NewMessage
     else Sub.none


view : Model -> Html Msg
view model =
  div [] [ button [onClick Toggle] [text "Toggle"] ]

Keyamoon avatar Jun 18 '17 10:06 Keyamoon

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot avatar Jun 18 '17 10:06 process-bot