Skip to content

Commit 2c8ecb4

Browse files
authored
fix: abort connection on TLS error (#3027)
If the TLS socket emits an error message, abort the connection if it is abortable. We should probably ammend the interface so `.abort` is relected in the types but this would be a bigger change.
1 parent 3f127b6 commit 2c8ecb4

File tree

1 file changed

+13
-0
lines changed
  • packages/connection-encrypter-tls/src

1 file changed

+13
-0
lines changed

packages/connection-encrypter-tls/src/tls.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ export class TLS implements ConnectionEncrypter {
157157
}
158158

159159
socket.destroy(err)
160+
161+
if (isAbortable(conn)) {
162+
conn.abort(err)
163+
}
164+
160165
reject(err)
161166
})
162167
socket.once('secure', () => {
@@ -179,3 +184,11 @@ export class TLS implements ConnectionEncrypter {
179184
})
180185
}
181186
}
187+
188+
interface Abortable {
189+
abort (err: Error): void
190+
}
191+
192+
function isAbortable <T> (obj: T & Partial<Abortable>): obj is T & Abortable {
193+
return typeof obj?.abort === 'function'
194+
}

0 commit comments

Comments
 (0)