Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handling for read ETIMEDOUT error #2846

Open
wants to merge 13 commits into
base: v6/develop
Choose a base branch
from
29 changes: 18 additions & 11 deletions src/controllers/rpc/publish-rpc-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,28 @@ class PublishController extends BaseController {

break;
case NETWORK_MESSAGE_TYPES.REQUESTS.PROTOCOL_REQUEST:
// eslint-disable-next-line no-case-declarations
dataSource = await this.operationIdService.getCachedOperationIdData(operationId);
await this.operationIdService.cacheOperationIdData(operationId, {
assertionId: dataSource.assertionId,
assertion: message.data.assertion,
});
command.name = handleRequestCommand;
command.data.keyword = message.data.keyword;
command.data.agreementId = dataSource.agreementId;
command.data.agreementData = dataSource.agreementData;
try {
// eslint-disable-next-line no-case-declarations
dataSource = await this.operationIdService.getCachedOperationIdData(
operationId,
);
await this.operationIdService.cacheOperationIdData(operationId, {
assertionId: dataSource.assertionId,
assertion: message.data.assertion,
});
command.name = handleRequestCommand;
command.data.keyword = message.data.keyword;
command.data.agreementId = dataSource.agreementId;
command.data.agreementData = dataSource.agreementData;
} catch (error) {
milosstanisavljevic marked this conversation as resolved.
Show resolved Hide resolved
milosstanisavljevic marked this conversation as resolved.
Show resolved Hide resolved
this.logger.error(
`Unable to handle publish request. Error message: ${error.message}`,
);
}
break;
default:
throw Error('unknown message type');
}

command.data = {
...command.data,
remotePeerId,
Expand Down
6 changes: 5 additions & 1 deletion src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ class Libp2pService {

removeCachedSession(operationId, keywordUuid, peerIdString) {
if (this.sessions[peerIdString]?.[operationId]?.[keywordUuid]?.stream) {
this.sessions[peerIdString][operationId][keywordUuid].stream.close();
try {
this.sessions[peerIdString][operationId][keywordUuid].stream.close();
} catch (error) {
this.logger.error(`Error closing session stream.Error: ${error.message}`);
milosstanisavljevic marked this conversation as resolved.
Show resolved Hide resolved
}
delete this.sessions[peerIdString][operationId];
this.logger.trace(
`Removed session for remotePeerId: ${peerIdString}, operationId: ${operationId}.`,
Expand Down
3 changes: 1 addition & 2 deletions src/service/operation-id-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ class OperationIdService {
}

async getCachedOperationIdData(operationId) {
if (this.memoryCachedHandlersData[operationId]) {
if (this.memoryCachedHandlersData[operationId]?.data) {
this.logger.debug(`Reading operation id: ${operationId} cached data from memory`);
return this.memoryCachedHandlersData[operationId].data;
}

this.logger.debug(`Reading operation id: ${operationId} cached data from file`);
const documentPath = this.fileService.getOperationIdDocumentPath(operationId);
let data;
Expand Down