Commit d4f3e6d8 authored by muXxer's avatar muXxer

Fixed deadlock at closing of the outgoingReq channel

parent 7dd7f104
......@@ -82,6 +82,12 @@ func (client *PowClient) Init() error {
}
func (client *PowClient) Close() {
client.pendingRequestsLock.Lock()
for _, pendingRequest := range client.pendingRequests {
close(pendingRequest.powResponseChan)
}
client.pendingRequestsLock.Unlock()
client.powStream.CloseSend()
client.connection.Close()
}
......@@ -113,6 +119,7 @@ func (client *PowClient) handleConnection() {
client.printMsg("Connection to server closed")
client.connectionError = err
client.connectionErrorOcurred <- true
close(client.connectionErrorOcurred)
return
}
......@@ -121,6 +128,7 @@ func (client *PowClient) handleConnection() {
client.printMsg(fmt.Sprintf("Failed to receive: %v", err))
client.connectionError = err
client.connectionErrorOcurred <- true
close(client.connectionErrorOcurred)
return
}
......@@ -137,16 +145,14 @@ func (client *PowClient) handleConnection() {
}()
// Requests
for {
for pendingPowRequest := range client.outgoingReq {
client.pendingRequestsLock.Lock()
client.pendingRequests[pendingPowRequest.powRequest.Identifier] = pendingPowRequest
client.pendingRequestsLock.Unlock()
for pendingPowRequest := range client.outgoingReq {
client.pendingRequestsLock.Lock()
client.pendingRequests[pendingPowRequest.powRequest.Identifier] = pendingPowRequest
client.pendingRequestsLock.Unlock()
err := client.powStream.Send(pendingPowRequest.powRequest)
if err != nil {
client.printMsg(fmt.Sprintf("Failed to send a message: %v", err))
}
err := client.powStream.Send(pendingPowRequest.powRequest)
if err != nil {
client.printMsg(fmt.Sprintf("Failed to send a message: %v", err))
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment