Skip to content

Commit 5a0c8f3

Browse files
committed
Recommend disabling automatic reconnect for Websocket
1 parent 694fed9 commit 5a0c8f3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

doc/src/guide/protocols.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ is sending Websocket frames using `gun:ws_send/3`.
8787

8888
Gun will send a `gun_ws` message for every frame received.
8989

90+
It is recommended to disable automatic reconnect when
91+
Websocket is used because Gun cannot automatically upgrade
92+
to Websocket on reconnect, and so an undetected disconnect
93+
may lead to many error messages from Gun.
94+
9095
=== Summary
9196

9297
The two following tables summarize the supported operations

doc/src/guide/websocket.asciidoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,20 @@ receive
122122
handle_frame(ConnPid, StreamRef, Frame)
123123
end.
124124
----
125+
126+
=== Automatic reconnect gotchas
127+
128+
It is recommended to disable automatic reconnect when
129+
Websocket is used because Gun cannot automatically upgrade
130+
to Websocket on reconnect, and so an undetected disconnect
131+
may lead to many error messages from Gun.
132+
133+
This can be done by setting the `retry` option to `0`
134+
when opening a connection:
135+
136+
[source,erlang]
137+
----
138+
{ok, ConnPid} = gun:open("localhost", 12345, #{
139+
retry ⇒ 0
140+
}).
141+
----

0 commit comments

Comments
 (0)