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

Fixed removal of the AbortSignal event listener #3227

Merged
merged 1 commit into from
Jul 17, 2024
Merged
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
19 changes: 9 additions & 10 deletions src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,17 @@ class Libp2pService {
let readResponseStart;
let readResponseEnd;
let response;
const abortSignalEventListener = async () => {
stream.abort();
response = null;
};
const timeoutController = new TimeoutController(timeout);
try {
readResponseStart = Date.now();

timeoutController.signal.addEventListener(
'abort',
async () => {
stream.abort();
response = null;
},
{ once: true },
);
timeoutController.signal.addEventListener('abort', abortSignalEventListener, {
once: true,
});

response = await this._readMessageFromStream(
stream,
Expand All @@ -420,12 +419,12 @@ class Libp2pService {
throw Error('Message timed out!');
}

timeoutController.signal.removeEventListener('abort');
timeoutController.signal.removeEventListener('abort', abortSignalEventListener);
timeoutController.clear();

readResponseEnd = Date.now();
} catch (error) {
timeoutController.signal.removeEventListener('abort');
timeoutController.signal.removeEventListener('abort', abortSignalEventListener);
timeoutController.clear();

readResponseEnd = Date.now();
Expand Down
Loading