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

[FSSDK-10180] close http request after getting response to release memory immediately (node) #927

Merged
merged 2 commits into from
May 13, 2024
Merged
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions lib/plugins/event_dispatcher/index.node.ts
pulak-opti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ export const dispatchEvent = function(
},
};

const reqWrapper: { req?: http.ClientRequest } = {};

const requestCallback = function(response?: { statusCode: number }): void {
if (response && response.statusCode && response.statusCode >= 200 && response.statusCode < 400) {
reqWrapper.req?.destroy();
callback(response);
}
pulak-opti marked this conversation as resolved.
Show resolved Hide resolved
};

const req = (parsedUrl.protocol === 'http:' ? http : https)
reqWrapper.req = (parsedUrl.protocol === 'http:' ? http : https)
.request(requestOptions, requestCallback as (res: http.IncomingMessage) => void);
// Add no-op error listener to prevent this from throwing
req.on('error', function() {});
req.write(dataString);
req.end();
return req;
reqWrapper.req.on('error', function() {});
pulak-opti marked this conversation as resolved.
Show resolved Hide resolved
reqWrapper.req.write(dataString);
reqWrapper.req.end();
return reqWrapper.req;
};

export default {
Expand Down
Loading