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 packet expiry error handling #3075

Open
mkurapov opened this issue Nov 4, 2024 · 0 comments
Open

Fix packet expiry error handling #3075

mkurapov opened this issue Nov 4, 2024 · 0 comments
Assignees
Labels
pkg: backend Changes in the backend package. type: bug Something isn't working

Comments

@mkurapov
Copy link
Contributor

mkurapov commented Nov 4, 2024

Bug Report

Currently, when the sending ILP connector sends a packet and it expires, we end up crashing the node process. This is because the packet expiry check is done via setTimeout, with the callback throwing an error that causes an uncaughtException. This leads to a SIGTERM, and the app crashes/exits.

export function createOutgoingExpireMiddleware() {
return async (
{ request, services: { logger } }: ILPContext,
next: () => Promise<void>
): Promise<void> => {
const { expiresAt } = request.prepare
const duration = expiresAt.getTime() - Date.now()
const timeout = setTimeout(() => {
logger.debug({ request }, 'packet expired')
throw new TransferTimedOutError('packet expired.')
}, duration)
await next().finally(() => {
clearTimeout(timeout)
})
}
}

Expected behavior

The node process does not crash/exit if a packet from the sending connector expires.

Additional context

setTimeout callbacks are treated in a separate call stack as part of the node event loop, this means they are handled outside of the code where they were registered.

@mkurapov mkurapov added the type: bug Something isn't working label Nov 4, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Rafiki Nov 4, 2024
@mkurapov mkurapov added the pkg: backend Changes in the backend package. label Nov 4, 2024
@sanducb sanducb self-assigned this Nov 19, 2024
@mkurapov mkurapov moved this from Backlog to Todo in Rafiki Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: bug Something isn't working
Projects
Status: In Progress
Development

No branches or pull requests

2 participants