Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Multiple open connections when subscription changes quickly #23

@Keyamoon

Description

@Keyamoon

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"] ]

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