@@ -4428,16 +4428,14 @@ channel_parse_messages(void)
44284428 int ret = FALSE;
44294429 int r ;
44304430 ch_part_T part = PART_SOCK ;
4431- static int recursive = FALSE ;
4431+ static int recursive = 0 ;
44324432#ifdef ELAPSED_FUNC
44334433 elapsed_T start_tv ;
44344434#endif
44354435
44364436 // The code below may invoke callbacks, which might call us back.
4437- // That doesn't work well, just return without doing anything.
4438- if (recursive )
4439- return FALSE;
4440- recursive = TRUE;
4437+ // In a recursive call channels will not be closed.
4438+ ++ recursive ;
44414439 ++ safe_to_invoke_callback ;
44424440
44434441#ifdef ELAPSED_FUNC
@@ -4454,33 +4452,37 @@ channel_parse_messages(void)
44544452 }
44554453 while (channel != NULL )
44564454 {
4457- if (channel_can_close (channel ))
4458- {
4459- channel -> ch_to_be_closed = (1U << PART_COUNT );
4460- channel_close_now (channel );
4461- // channel may have been freed, start over
4462- channel = first_channel ;
4463- continue ;
4464- }
4465- if (channel -> ch_to_be_freed || channel -> ch_killing )
4455+ if (recursive == 1 )
44664456 {
4467- channel_free_contents (channel );
4468- if (channel -> ch_job != NULL )
4469- channel -> ch_job -> jv_channel = NULL ;
4457+ if (channel_can_close (channel ))
4458+ {
4459+ channel -> ch_to_be_closed = (1U << PART_COUNT );
4460+ channel_close_now (channel );
4461+ // channel may have been freed, start over
4462+ channel = first_channel ;
4463+ continue ;
4464+ }
4465+ if (channel -> ch_to_be_freed || channel -> ch_killing )
4466+ {
4467+ channel_free_contents (channel );
4468+ if (channel -> ch_job != NULL )
4469+ channel -> ch_job -> jv_channel = NULL ;
44704470
4471- // free the channel and then start over
4472- channel_free_channel (channel );
4473- channel = first_channel ;
4474- continue ;
4475- }
4476- if (channel -> ch_refcount == 0 && !channel_still_useful (channel ))
4477- {
4478- // channel is no longer useful, free it
4479- channel_free (channel );
4480- channel = first_channel ;
4481- part = PART_SOCK ;
4482- continue ;
4471+ // free the channel and then start over
4472+ channel_free_channel (channel );
4473+ channel = first_channel ;
4474+ continue ;
4475+ }
4476+ if (channel -> ch_refcount == 0 && !channel_still_useful (channel ))
4477+ {
4478+ // channel is no longer useful, free it
4479+ channel_free (channel );
4480+ channel = first_channel ;
4481+ part = PART_SOCK ;
4482+ continue ;
4483+ }
44834484 }
4485+
44844486 if (channel -> ch_part [part ].ch_fd != INVALID_FD
44854487 || channel_has_readahead (channel , part ))
44864488 {
@@ -4521,7 +4523,7 @@ channel_parse_messages(void)
45214523 }
45224524
45234525 -- safe_to_invoke_callback ;
4524- recursive = FALSE ;
4526+ -- recursive ;
45254527
45264528 return ret ;
45274529}
0 commit comments