Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

fix: Never destroy sockets explicitly #437

Merged
merged 1 commit into from
Nov 24, 2020
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
16 changes: 0 additions & 16 deletions lib/protocol/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,10 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
let newSessionId;
let currentProtocol = extractProtocol(driver, req.params.sessionId);

let terminateSocket = false;

try {
// if this is a session command but we don't have a session,
// error out early (especially before proxying)
if (isSessCmd && !driver.sessionExists(req.params.sessionId)) {
terminateSocket = true;
throw new errors.NoSuchDriverError();
}

Expand Down Expand Up @@ -334,7 +331,6 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {

// delete should not return anything even if successful
if (spec.command === DELETE_SESSION_COMMAND) {
terminateSocket = true;
SESSIONS_CACHE.getLogger(req.params.sessionId, currentProtocol)
.debug(`Received response: ${_.truncate(JSON.stringify(driverRes), {length: MAX_LOG_BODY_LENGTH})}`);
SESSIONS_CACHE.getLogger(req.params.sessionId, currentProtocol).debug('But deleting session, so not returning');
Expand Down Expand Up @@ -398,12 +394,6 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
// Use the JSONWP status code (which is usually 500)
httpStatus = jsonwpRes[0];
}

// any error while creating a session should not continue holding onto
// the socket
if (spec.command === CREATE_SESSION_COMMAND) {
terminateSocket = true;
}
}

// decode the response, which is either a string or json
Expand All @@ -427,12 +417,6 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
httpResBody = formatStatus(httpResBody, httpStatus, currentProtocol);
res.status(httpStatus).json(httpResBody);
}

// in certain situations the socket should not be kept alive
if (terminateSocket) {
SESSIONS_CACHE.getLogger(req.params.sessionId || newSessionId, currentProtocol).debug(`Destroying socket connection`);
res.socket.destroy();
}
};
// add the method to the app
app[method.toLowerCase()](path, (req, res) => {
Expand Down