File tree Expand file tree Collapse file tree 3 files changed +36
-10
lines changed
Expand file tree Collapse file tree 3 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -207,21 +207,28 @@ export const makeChanStream = (
207207 const reader = stream . getReader ( ) ;
208208 const processStream = async ( ) => {
209209 try {
210+ console . log ( "[makeChanStream] Starting to process stream" ) ;
210211 while ( true ) {
211212 const { done, value } = await reader . read ( ) ;
212- if ( done ) break ;
213+ if ( done ) {
214+ console . log ( "[makeChanStream] Stream done" ) ;
215+ break ;
216+ }
217+ console . log ( `[makeChanStream] Sending chunk of size ${ value . length } ` ) ;
213218 await chan . send ( value ) ;
214219 }
220+ console . log ( "[makeChanStream] Closing channel" ) ;
215221 chan . close ( ) ;
216222 } catch ( err ) {
217223 // Handle errors gracefully, especially for Node.js/undici
224+ console . error ( "[makeChanStream] Error processing stream:" , err ) ;
218225 if ( ! chan . signal . aborted ) {
219- console . error ( "error processing stream" , err ) ;
220226 chan . close ( ) ;
221227 }
222228 }
223229 } ;
224230 processStream ( ) . catch ( ( err ) => {
231+ console . error ( "[makeChanStream] Unhandled error in processStream:" , err ) ;
225232 if ( ! chan . signal . aborted ) {
226233 console . error ( "error processing stream" , err ) ;
227234 }
Original file line number Diff line number Diff line change @@ -279,6 +279,7 @@ async function doFetch(
279279 headers [ key ] . push ( value ) ;
280280 } ) ;
281281
282+ console . log ( `[doFetch] Sending response-start for ${ request . id } , status: ${ response . status } ` ) ;
282283 await clientCh . send ( {
283284 type : "response-start" ,
284285 id : request . id ,
@@ -288,17 +289,35 @@ async function doFetch(
288289 } ) ;
289290
290291 const body = response ?. body ;
291- const stream = body ? makeChanStream ( body ) : undefined ;
292- for await ( const chunk of stream ?. recv ( signal ) ?? [ ] ) {
293- await clientCh . send ( {
294- type : "data" ,
295- id : request . id ,
296- chunk,
297- } ) ;
292+ console . log ( `[doFetch] Response body for ${ request . id } :` , body ? 'present' : 'null' ) ;
293+
294+ if ( body ) {
295+ try {
296+ const stream = makeChanStream ( body ) ;
297+ console . log ( `[doFetch] Reading response stream for ${ request . id } ` ) ;
298+ for await ( const chunk of stream . recv ( signal ) ) {
299+ console . log ( `[doFetch] Sending chunk for ${ request . id } , size: ${ chunk . length } ` ) ;
300+ await clientCh . send ( {
301+ type : "data" ,
302+ id : request . id ,
303+ chunk,
304+ } ) ;
305+ }
306+ console . log ( `[doFetch] Finished reading response stream for ${ request . id } ` ) ;
307+ } catch ( streamError ) {
308+ console . error ( `[doFetch] Stream error for ${ request . id } :` , streamError ) ;
309+ if ( ! signal . aborted ) {
310+ throw streamError ;
311+ }
312+ }
298313 }
314+
299315 if ( signal . aborted ) {
316+ console . log ( `[doFetch] Request ${ request . id } was aborted` ) ;
300317 return ;
301318 }
319+
320+ console . log ( `[doFetch] Sending data-end for ${ request . id } ` ) ;
302321 await clientCh . send ( {
303322 type : "data-end" ,
304323 id : request . id ,
Original file line number Diff line number Diff line change 11{
22 "name" : " @deco-cx/warp-node" ,
3- "version" : " 0.3.21-beta.1 " ,
3+ "version" : " 0.3.21-beta.2 " ,
44 "description" : " WebSocket tunneling library for Node.js and other runtimes" ,
55 "type" : " module" ,
66 "main" : " dist/mod.js" ,
You can’t perform that action at this time.
0 commit comments