@@ -161,24 +161,35 @@ export class DockerContainerClient implements ContainerClient {
161161 }
162162 }
163163
164- async logs ( container : Container , opts ?: ContainerLogsOptions ) : Promise < Readable > {
165- try {
166- log . debug ( `Fetching container logs...` , { containerId : container . id } ) ;
167- const stream = ( await container . logs ( {
164+ logs ( container : Container , opts ?: ContainerLogsOptions ) : Promise < Readable > {
165+ log . debug ( `Fetching container logs...` , { containerId : container . id } ) ;
166+
167+ const proxyStream = new PassThrough ( ) ;
168+ proxyStream . setEncoding ( "utf8" ) ;
169+
170+ container
171+ . logs ( {
168172 follow : true ,
169173 stdout : true ,
170174 stderr : true ,
171175 tail : opts ?. tail ?? - 1 ,
172176 since : opts ?. since ?? 0 ,
173- } ) ) as IncomingMessage ;
174- stream . socket . unref ( ) ;
175- const demuxedStream = this . demuxStream ( container . id , stream ) ;
176- log . debug ( `Fetched container logs` , { containerId : container . id } ) ;
177- return demuxedStream ;
178- } catch ( err ) {
179- log . error ( `Failed to fetch container logs: ${ err } ` , { containerId : container . id } ) ;
180- throw err ;
181- }
177+ } )
178+ . then ( async ( stream ) => {
179+ const actualLogStream = stream as IncomingMessage ;
180+ actualLogStream . socket ?. unref ( ) ;
181+
182+ const demuxedStream = await this . demuxStream ( container . id , actualLogStream ) ;
183+ demuxedStream . pipe ( proxyStream ) ;
184+ demuxedStream . on ( "error" , ( err ) => proxyStream . emit ( "error" , err ) ) ;
185+ demuxedStream . on ( "end" , ( ) => proxyStream . end ( ) ) ;
186+ } )
187+ . catch ( ( err ) => {
188+ log . error ( `Failed to fetch container logs: ${ err } ` , { containerId : container . id } ) ;
189+ proxyStream . end ( ) ;
190+ } ) ;
191+
192+ return Promise . resolve ( proxyStream ) ;
182193 }
183194
184195 async exec ( container : Container , command : string [ ] , opts ?: Partial < ExecOptions > ) : Promise < ExecResult > {
0 commit comments