Skip to content

Commit 3155069

Browse files
authored
Merge pull request #4 from mailsvb/fixClose
destroy open connections on close()
2 parents f723655 + 79b4f7e commit 3155069

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

lib/jsftpd.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class ftpd {
7777
}
7878
}
7979

80+
this.lastSocketKey = 0
81+
this.openSockets = {}
82+
8083
// setup FTP on TCP
8184
this._tcp = net.createServer()
8285
this._tcp.on('connection', (socket) => this.Handler(this, socket))
@@ -98,6 +101,7 @@ class ftpd {
98101
}
99102

100103
stop () {
104+
Object.keys(this.openSockets).forEach((socketKey) => this.openSockets[socketKey].destroy())
101105
this._tcp.close()
102106
this._useTLS && this._tls.close()
103107
}
@@ -125,6 +129,8 @@ class ftpd {
125129
Handler (main, socket) {
126130
const connectionInfo = `[${socket.remoteAddress.replace(/::ffff:/g, '')}] [${socket.remotePort}]`
127131
const localAddr = socket.localAddress.replace(/::ffff:/g, '')
132+
const socketKey = ++main.lastSocketKey
133+
main.openSockets[socketKey] = socket
128134
let authenticated = false
129135
let isSecure = socket.encrypted || false
130136
let protection = false
@@ -176,6 +182,7 @@ class ftpd {
176182
socket.on('data', dataHandler)
177183
socket.on('error', main.ErrorHandler)
178184
socket.on('close', () => {
185+
delete main.openSockets[socketKey]
179186
main.DebugHandler(`${connectionInfo} FTP connection closed`)
180187
if (ftpData) {
181188
ftpData.close()

0 commit comments

Comments
 (0)