igor-dv opened a new issue, #40414:
URL: https://github.com/apache/beam/issues/40414

   ### What happened?
   
   `DataChannelManager.closeInstruction` takes the manager lock
   
   ```go
   func (m *DataChannelManager) closeInstruction(...) {
       m.mu.Lock()
       defer m.mu.Unlock()
       ...
       err := ch.removeInstruction(instID)
   }
   ```
   
   Then `ch.removeInstruction(instID)` takes the channel lock:
   
   ```go
   func (c *DataChannel) removeInstruction(...) {
       c.mu.Lock()
       ...
   }
   ``` 
   
   If the stream fails (DataChannel.read):
   
   ```go
   c.mu.Lock()
   c.terminateStreamOnError(err)  // requires the lock to be held
   c.mu.Unlock()
   ```
   
   terminateStreamOnError (still under that lock) calls the callback:
   
   ```go
   func (c *DataChannel) terminateStreamOnError(err error) {
           ...
        if c.forceRecreate != nil {
                c.forceRecreate(c.id, err)
                c.forceRecreate = nil
        }
   }
   ```
   
   That callback is the one Open set, and that is where the manager lock is 
taken:
   
   ```go
   ch.forceRecreate = func(id string, err error) {
       ....
       m.mu.Lock()
       delete(m.ports, port.URL)
       m.mu.Unlock()
   }
   ```
   
   **So one thread is: c.mu → m.mu. The other (closeInstruction) is: m.mu → 
c.mu.**
   
   I would like forceRecreate to drop the port after releasing the channel 
lock, and only if this channel is still the one in the map (so a replacement 
from Open is not deleted).
   
   (Same problem with the StateChannel)
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [ ] Component: Python SDK
   - [ ] Component: Java SDK
   - [x] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Twister2 Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to