File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,16 @@ for easy modification.
267
267
*Default *: ``5.0 ``
268
268
269
269
270
+ ``constants.SOCKET_CLOSE_WAIT_TIMEOUT ``
271
+
272
+ Maximum time in seconds to wait for the socket's write buffer to get empty.
273
+ Set to 0 to disable waiting for the socket write buffer to get empty.
274
+
275
+ *Type *: ``float ``
276
+
277
+ *Default *: ``30.0 ``
278
+
279
+
270
280
``constants.QUEUE_CHECK_INTERVAL ``
271
281
272
282
Interval in seconds to check the internal queue for new messages
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ class Constants:
13
13
"""
14
14
# timeout in seconds for TCP connections
15
15
SOCKET_TIMEOUT = 5.0
16
+ # maximum time in seconds to wait for the socket's write buffer to get empty
17
+ SOCKET_CLOSE_WAIT_TIMEOUT = 30.0
16
18
# interval in seconds to check the internal queue for new messages to be cached in the database
17
19
QUEUE_CHECK_INTERVAL = 2.0
18
20
# interval in seconds to send cached events from the database to Logstash
Original file line number Diff line number Diff line change 18
18
import pylogbeat
19
19
import requests
20
20
21
+ from logstash_async .constants import constants
21
22
from logstash_async .utils import ichunked
22
23
23
24
@@ -126,12 +127,22 @@ def _convert_data_to_send(self, data):
126
127
def _close (self , force = False ):
127
128
if not self ._keep_connection or force :
128
129
if self ._sock :
129
- while not self ._is_sock_write_buff_empty ():
130
- time .sleep (0.05 )
130
+ self ._wait_for_socket_buffer_empty ()
131
131
self ._sock .shutdown (socket .SHUT_WR )
132
132
self ._sock .close ()
133
133
self ._sock = None
134
134
135
+ # ----------------------------------------------------------------------
136
+ def _wait_for_socket_buffer_empty (self ):
137
+ wait_timeout = constants .SOCKET_CLOSE_WAIT_TIMEOUT
138
+ interval = 0.05
139
+ time_waited = 0
140
+ # wait until the socket's write buffer is empty
141
+ # but do not wait longer than SOCKET_CLOSE_WAIT_TIMEOUT
142
+ while not self ._is_sock_write_buff_empty () and time_waited < wait_timeout :
143
+ time_waited += interval
144
+ time .sleep (interval )
145
+
135
146
# ----------------------------------------------------------------------
136
147
def _is_sock_write_buff_empty (self ):
137
148
socket_fd = self ._sock .fileno ()
You can’t perform that action at this time.
0 commit comments