From 8b34f9cb4c3437f3464704c56bf0f4879bec1e1c Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Fri, 19 Jun 2020 19:34:43 +0300 Subject: [PATCH] fix(xod-client, xod-client-electron): clear the queued chunks of a response data on connection close --- .../src/debugger/tetheringInetMiddleware.js | 14 +++++++++++++- packages/xod-client/src/debugger/actionTypes.js | 2 ++ packages/xod-client/src/debugger/actions.js | 4 ++++ packages/xod-client/src/debugger/reducer.js | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/xod-client-electron/src/debugger/tetheringInetMiddleware.js b/packages/xod-client-electron/src/debugger/tetheringInetMiddleware.js index f4c5ccff3..cec90c77f 100644 --- a/packages/xod-client-electron/src/debugger/tetheringInetMiddleware.js +++ b/packages/xod-client-electron/src/debugger/tetheringInetMiddleware.js @@ -73,6 +73,15 @@ const createListener = (dispatch, transmit, nodeId) => const isReadOkResponse = R.startsWith(ACK); +// In case that the connection is closed before than all request has been received +// there is no reason to continue sending the response data. +const clearQueueOnCloseConnection = R.curry((dispatch, command) => + R.when( + R.equals('AT+CIPCLOSE'), + R.compose(dispatch, client.tetheringInetClearChunks) + )(command) +); + export default ({ getState, dispatch }) => next => action => { const state = getState(); const result = next(action); @@ -86,7 +95,10 @@ export default ({ getState, dispatch }) => next => action => { const worker = action.payload.worker; const transmit = createTransmitter(dispatch, worker.sendToWasm); const listener = createListener(dispatch, transmit, nodeId); - const write = AtNet.create(listener); + const write = R.compose( + AtNet.create(listener), + R.tap(clearQueueOnCloseConnection(dispatch)) + ); dispatch( client.tetheringInetCreated( action.payload.tetheringInetNodeId, diff --git a/packages/xod-client/src/debugger/actionTypes.js b/packages/xod-client/src/debugger/actionTypes.js index d7704053a..dfdf558dc 100644 --- a/packages/xod-client/src/debugger/actionTypes.js +++ b/packages/xod-client/src/debugger/actionTypes.js @@ -31,3 +31,5 @@ export const TETHERING_INET_CREATED = 'TETHERING_INET_CREATED'; export const TETHERING_INET_CHUNKS_ADDED = 'TETHERING_INET_CHUNKS_ADDED'; export const TETHERING_INET_CHUNK_SENT = 'TETHERING_INET_CHUNK_SENT'; + +export const TETHERING_INET_CLEAR_CHUNKS = 'TETHERING_INET_CLEAR_CHUNKS'; diff --git a/packages/xod-client/src/debugger/actions.js b/packages/xod-client/src/debugger/actions.js index 1709db8df..b63801ba9 100644 --- a/packages/xod-client/src/debugger/actions.js +++ b/packages/xod-client/src/debugger/actions.js @@ -106,3 +106,7 @@ export const tetheringInetChunkSent = () => (dispatch, getState) => { }); return maybeProp(0, chunksToSend); }; + +export const tetheringInetClearChunks = () => ({ + type: AT.TETHERING_INET_CLEAR_CHUNKS, +}); diff --git a/packages/xod-client/src/debugger/reducer.js b/packages/xod-client/src/debugger/reducer.js index 16e83845b..161288ff6 100644 --- a/packages/xod-client/src/debugger/reducer.js +++ b/packages/xod-client/src/debugger/reducer.js @@ -23,6 +23,7 @@ import { TETHERING_INET_CREATED, TETHERING_INET_CHUNKS_ADDED, TETHERING_INET_CHUNK_SENT, + TETHERING_INET_CLEAR_CHUNKS, } from './actionTypes'; import * as EAT from '../editor/actionTypes'; @@ -531,6 +532,8 @@ export default (state = initialState, action) => { R.tail, state ); + case TETHERING_INET_CLEAR_CHUNKS: + return R.assocPath(['tetheringInet', 'chunksToSend'], [], state); case EAT.TABTEST_RUN_REQUESTED: return R.compose(