Only close websockets when connection is open (#44304)

This addresses a problem where Safari's websockets gets permanently broken
when closing them in a "connecting" state.

See https://github.com/rails/rails/issues/43835#issuecomment-1002288478
This commit is contained in:
Jorge Manrubia 2022-02-02 15:50:34 +01:00 committed by GitHub
parent bad8e77335
commit ed8e767218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 4 deletions

View File

@ -166,7 +166,7 @@
if (!allowReconnect) {
this.monitor.stop();
}
if (this.isActive()) {
if (this.isOpen()) {
return this.webSocket.close();
}
}

View File

@ -172,7 +172,7 @@ class Connection {
if (!allowReconnect) {
this.monitor.stop();
}
if (this.isActive()) {
if (this.isOpen()) {
return this.webSocket.close();
}
}

View File

@ -166,7 +166,7 @@
if (!allowReconnect) {
this.monitor.stop();
}
if (this.isActive()) {
if (this.isOpen()) {
return this.webSocket.close();
}
}

View File

@ -44,7 +44,8 @@ class Connection {
close({allowReconnect} = {allowReconnect: true}) {
if (!allowReconnect) { this.monitor.stop() }
if (this.isActive()) {
// Avoid closing websockets in a "connecting" state due to Safari 15.1+ bug. See: https://github.com/rails/rails/issues/43835#issuecomment-1002288478
if (this.isOpen()) {
return this.webSocket.close()
}
}