Skip to content

Commit 2605d8c

Browse files
Check if socket is already closed
1 parent a734439 commit 2605d8c

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"lz4js": "^0.2.0"
4646
},
4747
"devDependencies": {
48-
"@types/jest": "^29.5.7",
48+
"@types/jest": "^29.5.11",
4949
"@types/lz4": "^0.6.3",
5050
"@types/node": "^12.20.55",
5151
"@typescript-eslint/eslint-plugin": "^4.22.0",
@@ -59,7 +59,7 @@
5959
"prettier": "^2.2.1",
6060
"sqlite3": "^5.1.6",
6161
"ts-jest": "^29.1.1",
62-
"ts-node": "^10.9.1",
62+
"ts-node": "^10.9.2",
6363
"typedoc": "^0.25.3",
6464
"typedoc-plugin-markdown": "^3.17.1",
6565
"typescript": "^4.9.5"

src/connection.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const lz4 = require('lz4js')
99
import { SQLiteCloudConfig, SQLCloudRowsetMetadata, SQLiteCloudError, SQLiteCloudDataTypes, ErrorCallback, ResultsCallback } from './types'
1010
import { SQLiteCloudRowset } from './rowset'
1111
import { parseConnectionString, parseBoolean } from './utilities'
12-
import { Socket } from 'net'
1312

1413
/**
1514
* The server communicates with clients via commands defined
@@ -163,9 +162,9 @@ export class SQLiteCloudConnection {
163162
this.socket.removeAllListeners('data')
164163
this.socket.removeAllListeners('error')
165164
this.socket.removeAllListeners('close')
166-
}
167-
if (error) {
168-
this.close()
165+
if (error) {
166+
this.close()
167+
}
169168
}
170169
done(error)
171170
}
@@ -190,7 +189,7 @@ export class SQLiteCloudConnection {
190189
console.assert(this.socket, 'Connection already closed')
191190
const commands = this.initializationCommands
192191
this.processCommands(commands, error => {
193-
if (error) {
192+
if (error && this.socket) {
194193
this.close()
195194
}
196195
if (callback) {
@@ -357,7 +356,7 @@ export class SQLiteCloudConnection {
357356

358357
/** Disconnect from server, release connection. */
359358
public close(): this {
360-
console.assert(this.socket !== undefined, 'SQLiteCloudConnection.close - connection already closed')
359+
console.assert(this.socket !== null, 'SQLiteCloudConnection.close - connection already closed')
361360
if (this.socket) {
362361
this.socket.destroy()
363362
this.socket = null

0 commit comments

Comments
 (0)