mirror of
https://github.com/cryptonote-social/csminer.git
synced 2024-09-11 05:35:23 +03:00
more fixes for stratum client locking, timeouts, etc
This commit is contained in:
parent
3e7568e0b5
commit
61990e4918
10
miner.go
10
miner.go
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user