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

fix: disallow floating promises #704

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
'no-console': 'error',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'import/no-cycle': 'error',
'import/newline-after-import': ['error', { count: 1 }],
'import/order': [
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ export class Agent {
}

for (const transport of this.inboundTransports) {
transport.start(this)
await transport.start(this)
}

for (const transport of this.outboundTransports) {
transport.start(this)
await transport.start(this)
}

// Connect to mediator through provided invitation if provided in config
Expand All @@ -201,10 +201,10 @@ export class Agent {

// Stop transports
for (const transport of this.outboundTransports) {
transport.stop()
await transport.stop()
}
for (const transport of this.inboundTransports) {
transport.stop()
await transport.stop()
}
Copy link
Contributor

@jakubkoci jakubkoci Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to do something like await Promises.all(this.inboundTransports.map(t => t.stop()))? I think we just need to wait until all transports finish

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I'll address in a seperate PR


// close wallet if still initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class CredentialService {
// Update record
credentialRecord.proposalMessage = proposalMessage
credentialRecord.credentialAttributes = proposalMessage.credentialProposal?.attributes
this.updateState(credentialRecord, CredentialState.ProposalSent)
await this.updateState(credentialRecord, CredentialState.ProposalSent)

return { message: proposalMessage, credentialRecord }
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/proofs/services/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class ProofService {

// Update record
proofRecord.proposalMessage = proposalMessage
this.updateState(proofRecord, ProofState.ProposalSent)
await this.updateState(proofRecord, ProofState.ProposalSent)

return { message: proposalMessage, proofRecord }
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/routing/RecipientModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class RecipientModule {
this.logger.warn(
`Websocket connection to mediator with connectionId '${mediator.connectionId}' is closed, attempting to reconnect...`
)
this.openMediationWebSocket(mediator)
await this.openMediationWebSocket(mediator)
})

await this.openMediationWebSocket(mediator)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/HttpOutboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class HttpOutboundTransport implements OutboundTransport {
)
return
}
this.agent.receiveMessage(encryptedMessage)
await this.agent.receiveMessage(encryptedMessage)
} catch (error) {
this.logger.debug('Unable to parse response message')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transport/WsOutboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class WsOutboundTransport implements OutboundTransport {
)
}
this.logger.debug('Payload received from mediator:', payload)
this.agent.receiveMessage(payload)
void this.agent.receiveMessage(payload)
}

private listenOnWebSocketMessages(socket: WebSocket) {
Expand Down
2 changes: 1 addition & 1 deletion samples/mediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ const run = async () => {
})
}

run()
void run()