more fixes for stratum client locking, timeouts, etc

This commit is contained in:
cryptonote-social 2020-08-01 10:23:08 -07:00
parent 3e7568e0b5
commit 61990e4918
2 changed files with 39 additions and 11 deletions

View File

@ -194,7 +194,9 @@ func connectClient(cl *client.Client, uname, rigid string, startDiff int, config
}
config += "start_diff=" + strconv.Itoa(startDiff)
}
clMutex.Lock()
err := cl.Connect(uname, config, rigid, useTLS)
clMutex.Unlock()
if err != nil {
crylog.Warn("Client failed to connect:", err)
time.Sleep(sleepSec)
@ -213,9 +215,11 @@ func connectClient(cl *client.Client, uname, rigid string, startDiff int, config
crylog.Error("Job dispatcher exitted with error:", err)
}
clMutex.Lock()
clientAlive = false
if clientAlive {
clientAlive = false
cl.Close()
}
clMutex.Unlock()
cl.Close()
}()
crylog.Info("Connected")
@ -305,6 +309,8 @@ func goMine(wg *sync.WaitGroup, job client.MultiClientJob, thread int) {
resp, err := cl.SubmitWork(fnonce, jobid)
if err != nil {
crylog.Warn("Submit work client failure:", jobid, err)
clientAlive = false
cl.Close()
return
}
if len(resp.Error) > 0 {

View File

@ -166,20 +166,31 @@ func (cl *Client) SubmitMulticlientWork(username string, rigid string, nonce str
crylog.Error("json marshalling failed:", err, "for client:", cl)
return nil, err
}
cl.conn.SetWriteDeadline(time.Now().Add(60 * time.Second))
cl.conn.SetWriteDeadline(time.Now().Add(30 * time.Second))
data = append(data, '\n')
if _, err = cl.conn.Write(data); err != nil {
crylog.Error("writing request failed:", err, "for client:", cl)
return nil, err
}
response := <-cl.responseChannel
timeout := make(chan bool)
go func() {
time.Sleep(30 * time.Second)
timeout <- true
}()
var response *SubmitWorkResponse
select {
case response = <-cl.responseChannel:
case <-timeout:
crylog.Error("response timeout")
return nil, fmt.Errorf("submit work failure: response timeout")
}
if response == nil {
crylog.Error("Got nil response")
return nil, fmt.Errorf("submit work failure 1")
return nil, fmt.Errorf("submit work failure: nil response")
}
if response.ID != SUBMIT_WORK_JSON_ID {
crylog.Error("Got unexpected response:", response.ID)
return nil, fmt.Errorf("submit work failure 2")
return nil, fmt.Errorf("submit work failure: unexpected response")
}
return response, nil
}
@ -211,14 +222,25 @@ func (cl *Client) SubmitWork(nonce string, jobid string) (*SubmitWorkResponse, e
crylog.Error("writing request failed:", err, "for client:", cl)
return nil, err
}
response := <-cl.responseChannel
timeout := make(chan bool)
go func() {
time.Sleep(30 * time.Second)
timeout <- true
}()
var response *SubmitWorkResponse
select {
case response = <-cl.responseChannel:
case <-timeout:
crylog.Error("response timeout")
return nil, fmt.Errorf("submit work failure: response timeout")
}
if response == nil {
crylog.Error("Got nil response")
return nil, fmt.Errorf("submit work failure 1")
crylog.Error("got nil response")
return nil, fmt.Errorf("submit work failure: nil response")
}
if response.ID != SUBMIT_WORK_JSON_ID {
crylog.Error("Got unexpected response:", response.ID)
return nil, fmt.Errorf("submit work failure 2")
crylog.Error("got unexpected response:", response.ID)
return nil, fmt.Errorf("submit work failure: unexpected response")
}
return response, nil
}