Commit d5048f49 authored by muXxer's avatar muXxer

Finally fixed send on closed outgoingReq channel, hopefully

parent 730e6a8a
......@@ -92,6 +92,8 @@ func (client *PowClient) Close() {
client.signalClosed = true
close(client.signalChanQuit)
close(client.outgoingReq)
close(client.connectionErrorOcurred)
client.pendingRequestsLock.Lock()
for _, pendingRequest := range client.pendingRequests {
......@@ -122,21 +124,23 @@ func (client *PowClient) handleConnection() {
// Responses
go func() {
defer client.Close()
for {
incomingRes, err := client.powStream.Recv()
if err == io.EOF {
close(client.outgoingReq)
// read done.
client.printMsg("Connection to server closed")
client.connectionError = err
close(client.connectionErrorOcurred)
return
}
if err != nil {
close(client.outgoingReq)
client.printMsg(fmt.Sprintf("Failed to receive: %v", err))
_, ok := <-client.signalChanQuit
if !ok {
return
}
if err == io.EOF {
client.printMsg("Connection to server closed")
} else {
client.printMsg(fmt.Sprintf("Failed to receive: %v", err))
}
client.connectionError = err
close(client.connectionErrorOcurred)
return
......@@ -147,8 +151,9 @@ func (client *PowClient) handleConnection() {
client.pendingRequestsLock.Lock()
pendingPowRequest, ok := client.pendingRequests[incomingRes.Identifier]
if ok {
if !client.signalClosed {
pendingPowRequest.powResponseChan <- incomingRes
select {
case <-client.signalChanQuit:
case pendingPowRequest.powResponseChan <- incomingRes:
}
delete(client.pendingRequests, incomingRes.Identifier)
}
......@@ -196,10 +201,8 @@ func (client *PowClient) PowFunc(trytes trinary.Trytes, minWeightMagnitude int,
pendingPowRequest := PendingPowRequest{powRequest: &api.PowRequest{Identifier: reqID, Trytes: string(trytes), Mwm: uint32(minWeightMagnitude)}, powResponseChan: make(chan *api.PowResponse, 1)}
select {
case <-client.signalChanQuit:
return "", errors.New("PowClient was closed")
case client.outgoingReq <- pendingPowRequest:
}
......
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