File tree 1 file changed +13
-6
lines changed
lib/plugins/event_dispatcher
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * Copyright 2016-2018, 2020-2021, Optimizely
2
+ * Copyright 2016-2018, 2020-2021, 2024 Optimizely
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -51,19 +51,26 @@ export const dispatchEvent = function(
51
51
} ,
52
52
} ;
53
53
54
+ const reqWrapper : { req ?: http . ClientRequest } = { } ;
55
+
54
56
const requestCallback = function ( response ?: { statusCode : number } ) : void {
55
57
if ( response && response . statusCode && response . statusCode >= 200 && response . statusCode < 400 ) {
56
58
callback ( response ) ;
57
59
}
60
+ reqWrapper . req ?. destroy ( ) ;
61
+ reqWrapper . req = undefined ;
58
62
} ;
59
63
60
- const req = ( parsedUrl . protocol === 'http:' ? http : https )
64
+ reqWrapper . req = ( parsedUrl . protocol === 'http:' ? http : https )
61
65
. request ( requestOptions , requestCallback as ( res : http . IncomingMessage ) => void ) ;
62
66
// Add no-op error listener to prevent this from throwing
63
- req . on ( 'error' , function ( ) { } ) ;
64
- req . write ( dataString ) ;
65
- req . end ( ) ;
66
- return req ;
67
+ reqWrapper . req . on ( 'error' , function ( ) {
68
+ reqWrapper . req ?. destroy ( ) ;
69
+ reqWrapper . req = undefined ;
70
+ } ) ;
71
+ reqWrapper . req . write ( dataString ) ;
72
+ reqWrapper . req . end ( ) ;
73
+ return reqWrapper . req ;
67
74
} ;
68
75
69
76
export default {
You can’t perform that action at this time.
0 commit comments