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