From 9f3309fc7dbc0e1f9ef15540b7f9353a35767025 Mon Sep 17 00:00:00 2001 From: Kevin Schiffer Date: Mon, 11 Dec 2023 13:46:16 +0900 Subject: [PATCH] console: Fix stream reconnection --- pkg/webui/console/lib/events/definitions.js | 8 +++----- pkg/webui/console/store/middleware/logics/events.js | 13 ++++++------- pkg/webui/locales/en.json | 6 +++--- sdk/js/src/api/stream/subscribeToWebSocketStream.js | 3 +++ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/webui/console/lib/events/definitions.js b/pkg/webui/console/lib/events/definitions.js index a46406c162..d404fd629e 100644 --- a/pkg/webui/console/lib/events/definitions.js +++ b/pkg/webui/console/lib/events/definitions.js @@ -43,15 +43,13 @@ export const eventMessages = { 'synthetic.status.reconnected:type': 'Stream reconnected', 'synthetic.status.reconnected:preview': 'The stream connection has been re-established', - 'synthetic.status.reconnected:details': - 'The Console was able to reconnect to the internet and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will not be re-delivered.', + 'The Console was able to reconnect to the network and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will only be re-delivered within the range of the event retention configuration for your network.', 'synthetic.status.closed:type': 'Stream connection closed', - 'synthetic.status.closed:preview': 'The connection was closed by the stream provider', - + 'synthetic.status.closed:preview': 'The connection was closed', 'synthetic.status.closed:details': - 'The Console received a close signal from the stream provider. This usually means that the backend server shut down. This can have various causes, such as scheduled maintenance or malfunction which caused a forced restart. The Console will then reconnect automatically once the stream provider becomes available again.', + 'The event stream was closed. This can be for various reasons, such as your machine going into standby mode or the internet connection being interrupted. The stream will reconnect automatically once the internet connection has been re-established.', 'synthetic.status.cleared:type': 'Events cleared', 'synthetic.status.cleared:preview': 'The events list has been cleared', diff --git a/pkg/webui/console/store/middleware/logics/events.js b/pkg/webui/console/store/middleware/logics/events.js index fcf45003fc..7d6c0b0b1d 100644 --- a/pkg/webui/console/store/middleware/logics/events.js +++ b/pkg/webui/console/store/middleware/logics/events.js @@ -1,4 +1,4 @@ -// Copyright © 2023 The Things Network Foundation, The Things Industries B.V. +// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -132,15 +132,14 @@ const createEventsConnectLogics = (reducerName, entityName, onEventsStart) => { try { channel = await onEventsStart([id], filterRegExp, EVENT_TAIL, after) + dispatch(startEventsSuccess(id, { silent })) - channel.on('open', () => dispatch(startEventsSuccess(id, { silent }))) channel.on('message', message => dispatch(getEventSuccess(id, message))) channel.on('error', error => dispatch(getEventFailure(id, error))) - channel.on('close', wasClientRequest => - dispatch(closeEvents(id, { silent: wasClientRequest })), - ) - - channel.on('open', () => dispatch(startEventsSuccess(id, { silent }))) + channel.on('close', wasClientRequest => { + dispatch(closeEvents(id, { silent: wasClientRequest })) + channel = null + }) } catch (error) { if (isUnauthenticatedError(error)) { // The user is no longer authenticated; reinitiate the auth flow diff --git a/pkg/webui/locales/en.json b/pkg/webui/locales/en.json index fe0159557d..334ecdaf14 100644 --- a/pkg/webui/locales/en.json +++ b/pkg/webui/locales/en.json @@ -613,10 +613,10 @@ "console.lib.events.definitions.synthetic.status.reconnecting:details": "The Console will periodically try to reconnect to the event stream if the connection was interrupted.", "console.lib.events.definitions.synthetic.status.reconnected:type": "Stream reconnected", "console.lib.events.definitions.synthetic.status.reconnected:preview": "The stream connection has been re-established", - "console.lib.events.definitions.synthetic.status.reconnected:details": "The Console was able to reconnect to the internet and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will not be re-delivered.", + "console.lib.events.definitions.synthetic.status.reconnected:details": "The Console was able to reconnect to the network and resumed the event stream. Subsequent event data will be received and displayed. Note that event data which was possibly emitted during the network disruption will only be re-delivered within the range of the event retention configuration for your network.", "console.lib.events.definitions.synthetic.status.closed:type": "Stream connection closed", - "console.lib.events.definitions.synthetic.status.closed:preview": "The connection was closed by the stream provider", - "console.lib.events.definitions.synthetic.status.closed:details": "The Console received a close signal from the stream provider. This usually means that the backend server shut down. This can have various causes, such as scheduled maintenance or malfunction which caused a forced restart. The Console will then reconnect automatically once the stream provider becomes available again.", + "console.lib.events.definitions.synthetic.status.closed:preview": "The connection was closed", + "console.lib.events.definitions.synthetic.status.closed:details": "The event stream was closed. This can be for various reasons, such as your machine going into standby mode or the internet connection being interrupted. The stream will reconnect automatically once the internet connection has been re-established.", "console.lib.events.definitions.synthetic.status.cleared:type": "Events cleared", "console.lib.events.definitions.synthetic.status.cleared:preview": "The events list has been cleared", "console.lib.events.definitions.synthetic.status.cleared:details": "The list of displayed events has been cleared.", diff --git a/sdk/js/src/api/stream/subscribeToWebSocketStream.js b/sdk/js/src/api/stream/subscribeToWebSocketStream.js index 3b0762118a..7d38acebbb 100644 --- a/sdk/js/src/api/stream/subscribeToWebSocketStream.js +++ b/sdk/js/src/api/stream/subscribeToWebSocketStream.js @@ -111,6 +111,9 @@ export default async ( // Event listener for 'close' wsInstances[url].addEventListener('close', closeEvent => { + // TODO: Handle close event codes. + // https://github.com/TheThingsNetwork/lorawan-stack/issues/6752 + delete wsInstances[url] Object.values(subscriptions) .filter(s => s.url === url)