Skip to content

Race Condition in CentralManagerImpl #217

@LionZXY

Description

@LionZXY

I found that the following code is used inside the CentralManagerImpl class

lateinit var internalScope: CoroutineScope

init {
 closeJob = scope.launch {
  internalScope = this
  //...
 }
}
//...
protected fun peripheral(id: ID, factory: (ID) -> P): P {
// ...
 state
  .launchIn(internalScope)
}

The problem with this code is that if internalScope has not been initialised, we will get an exception. For example this code:

val centralManager = CentralManagerImpl(scope)
centralManager.peripheral(ID) { } 

Can throw UninitializedPropertyAccessException if internalScope will not have time to reach execution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions