Skip to content

Commit

Permalink
🐛 Also close udp socket when throwing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GiyoMoon committed Jan 3, 2022
1 parent 97d7f06 commit bccbdad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steam-server-query",
"version": "1.1.1",
"version": "1.1.2",
"description": "Module which implements the Master Server Query Protocol and Game Server Queries.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions src/gameServer/gameServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class GameServerQuery {
try {
resultBuffer = await this._promiseSocket.send(this._buildInfoPacket(), this._host, this._port);
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}

Expand All @@ -80,6 +81,7 @@ class GameServerQuery {
try {
resultBuffer = await this._promiseSocket.send(this._buildInfoPacket(challenge), this._host, this._port);
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}
}
Expand All @@ -95,6 +97,7 @@ class GameServerQuery {
try {
challengeResultBuffer = await this._promiseSocket.send(this._buildPacket(Buffer.from([0x55])), this._host, this._port);
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}

Expand All @@ -104,6 +107,7 @@ class GameServerQuery {
try {
resultBuffer = await this._promiseSocket.send(this._buildPacket(Buffer.from([0x55]), challenge), this._host, this._port);
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}

Expand All @@ -118,6 +122,7 @@ class GameServerQuery {
try {
challengeResultBuffer = await this._promiseSocket.send(this._buildPacket(Buffer.from([0x56])), this._host, this._port);
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}

Expand All @@ -127,6 +132,7 @@ class GameServerQuery {
try {
resultBuffer = await this._promiseSocket.send(this._buildPacket(Buffer.from([0x56]), challenge), this._host, this._port);
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}

Expand Down
2 changes: 2 additions & 0 deletions src/masterServer/masterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MasterServerQuery {
resultBuffer = await this._promiseSocket.send(this._buildPacket(), this._host, this._port);
// catch promise rejections and throw error
} catch (err: any) {
this._promiseSocket.closeSocket();
throw new Error(err);
}

Expand All @@ -53,6 +54,7 @@ class MasterServerQuery {
this._hosts.length >= this._maxHosts &&
this._hosts[this._maxHosts - 1] !== ZERO_IP
) {
this._promiseSocket.closeSocket();
return this._hosts.slice(0, this._maxHosts);
}
} while (this._seedId !== ZERO_IP);
Expand Down

0 comments on commit bccbdad

Please sign in to comment.