@@ -21,6 +21,7 @@ local ipairs = ipairs
2121local table = table
2222local now = ngx .now
2323local type = type
24+ local exiting = ngx .worker .exiting
2425local batch_processor = {}
2526local batch_processor_mt = {
2627 __index = batch_processor
@@ -52,9 +53,12 @@ local function schedule_func_exec(self, delay, batch)
5253 local hdl , err = timer_at (delay , execute_func , self , batch )
5354 if not hdl then
5455 if err == " process exiting" then
55- -- it is allowed to create zero-delay timers even when
56- -- the Nginx worker process starts shutting down
57- timer_at (0 , execute_func , self )
56+ local hdl2 , err2 = timer_at (0 , execute_func , self , batch )
57+ if not hdl2 then
58+ core .log .error (" failed to create fallback process timer " ,
59+ " while exiting: " , err2 )
60+ return
61+ end
5862 else
5963 core .log .error (" failed to create process timer: " , err )
6064 return
118122
119123
120124local function flush_buffer (premature , self )
121- if now () - self .last_entry_t >= self .inactive_timeout or
125+ if premature or exiting () or
126+ now () - self .last_entry_t >= self .inactive_timeout or
122127 now () - self .first_entry_t >= self .buffer_duration
123128 then
124129 core .log .debug (" Batch Processor[" , self .name ," ] buffer " ,
0 commit comments