You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Nicholas Telford (Jira)" <ji...@apache.org> on 2024/09/05 10:58:00 UTC

[jira] [Resolved] (KAFKA-17487) Race in GlobalStreamThread initialization

     [ https://issues.apache.org/jira/browse/KAFKA-17487?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nicholas Telford resolved KAFKA-17487.
--------------------------------------
    Resolution: Duplicate

I mistakenly created this issue before pulling trunk, which has already been fixed!

> Race in GlobalStreamThread initialization
> -----------------------------------------
>
>                 Key: KAFKA-17487
>                 URL: https://issues.apache.org/jira/browse/KAFKA-17487
>             Project: Kafka
>          Issue Type: Bug
>          Components: streams
>    Affects Versions: 4.0.0
>            Reporter: Nicholas Telford
>            Assignee: Nicholas Telford
>            Priority: Minor
>
> When initializing the {{{}GlobalStreamThread{}}}, we {{countDown}} the {{initializationLatch}} _before_ setting the state to {{{}RUNNING{}}}.
> This can cause other threads waiting on that latch, most notably through {{{}GlobalStreamThread#start{}}}, to unblock before the thread state transitions to {{{}RUNNING{}}}.
> This mostly affects {{{}GlobalStreamThreadTest{}}}, in particular:
>  * {{{}shouldBeRunningAfterSuccessfulStart{}}}, which waits on {{GlobalStreamThread#start}} and then immediately asserts that the state is {{{}RUNNING{}}}, which due to this race, it sometimes isn't (yet).
>  * {{{}shouldStopRunningWhenClosedByUser{}}}, which waits on {{GlobalStreamThread#start}} and then immediately calls {{{}GlobalStreamThread#shutdown{}}}, which changes the state to {{{}PENDING_SHUTDOWN{}}}. The {{GlobalStreamThread}} then attempts to transition the state to {{{}RUNNING{}}}, which fails because it's not a valid transition from {{{}PENDING_SHUTDOWN{}}}.
> The fix is simple: move the {{setState(RUNNING)}} into {{{}#initialize{}}}, immediately before returning. This ensures that the state is set _before_ counting down the initialization latch.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)