|
1 | 1 | import { logger } from '../logger';
|
2 | 2 | import { SftpSessionHandler } from './SftpSessionHandler';
|
3 |
| -import type { SFTPWrapper } from 'ssh2'; |
| 3 | +import type { |
| 4 | + Session, |
| 5 | + SFTPWrapper, |
| 6 | +} from 'ssh2'; |
4 | 7 |
|
5 | 8 | export class SshSessionHandler {
|
6 | 9 | private readonly authToken: string;
|
7 | 10 |
|
8 |
| - public constructor(authToken: string) { |
| 11 | + private readonly session: Session; |
| 12 | + |
| 13 | + public constructor( |
| 14 | + session: Session, |
| 15 | + authToken: string, |
| 16 | + ) { |
| 17 | + this.session = session; |
9 | 18 | this.authToken = authToken;
|
10 | 19 | }
|
11 | 20 |
|
@@ -50,4 +59,20 @@ export class SshSessionHandler {
|
50 | 59 | public onClose = (): void => {
|
51 | 60 | logger.verbose('SSH session closed');
|
52 | 61 | };
|
| 62 | + |
| 63 | + public onEof = (): void => { |
| 64 | + // This addresses a bug in the ssh2 library where EOF is not properly |
| 65 | + // handled for sftp connections. |
| 66 | + // An upstream PR that would fix the behavior: https://github.com/mscdex/ssh2/pull/1111 |
| 67 | + // And some context from our own debugging: https://github.com/PermanentOrg/sftp-service/issues/45 |
| 68 | + // |
| 69 | + // The solution here is not ideal, as it is accessing an undocumented attribute that |
| 70 | + // doesn't exist in TypeScript. As a result I need to disable typescript checks. |
| 71 | + // |
| 72 | + // Once upstream makes that patch this entire handler should become completely unnecessary |
| 73 | + // |
| 74 | + // !!BEWARE: THERE BE DRAGONS HERE!! |
| 75 | + // @ts-expect-error because `_channel` is private / isn't actually documented. |
| 76 | + this.session._channel.end(); // eslint-disable-line max-len, no-underscore-dangle, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access |
| 77 | + }; |
53 | 78 | }
|
0 commit comments