diff --git a/server/main.go b/server/main.go index 0be69dc..2be21c0 100644 --- a/server/main.go +++ b/server/main.go @@ -14,7 +14,7 @@ import ( ) var ( - version = "2.0.2" + version = "2.0.3" // cmd line options configFile *string diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index ff24426..1001f4a 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -142,18 +142,12 @@ func NewProxy(id uint64) *Proxy { miniResult: math.MaxUint64, notify: make(chan []byte, 2), } - // go p.deleteIdle() p.SS = stratum.NewServer() p.SS.RegisterName("mining", &Mining{}) return p } -// func (p *Proxy) deleteIdle() { -// <-time.After(35 * time.Second) -// p.Delete() -// } - func (p *Proxy) Run(minerName string) { retryTimes := 3 if config.Get().TryPoolTimes > 0 { @@ -585,7 +579,20 @@ func (p *Proxy) Remove(w Worker) { if p.isClosed { return } - p.done <- 0 + + if p.Conn != nil { + p.Conn.Close() + } + + p.director.removeProxy(p.ID) + p.worker = nil + p.SS = nil + p.director = nil + + logger.Get().Printf("Proxy[%d] removed", p.ID) + p.Conn = nil + close(p.done) + p.isClosed = true } // CreateJob builds a job for distribution to a worker diff --git a/server/tcp/server.go b/server/tcp/server.go index 9f9211e..4a12555 100644 --- a/server/tcp/server.go +++ b/server/tcp/server.go @@ -47,7 +47,7 @@ func StartServer() { if err != nil { logger.Get().Println("Unable to accept connection: ", err) } - conn.SetReadDeadline(time.Now().Add(90 * time.Second)) + conn.SetReadDeadline(time.Now().Add(45 * time.Second)) // if !limit.Allow() { // logger.Get().Println("Out of rate limit:", rl, "per 25 ms.") diff --git a/server/tcp/worker.go b/server/tcp/worker.go index 1208255..a6589c5 100644 --- a/server/tcp/worker.go +++ b/server/tcp/worker.go @@ -34,7 +34,9 @@ func SpawnWorker(conn net.Conn) { conn: conn, //jobs: make(chan *proxy.Job), } - ctx := context.WithValue(context.Background(), "worker", w) + ctxTimeout, cancel := context.WithTimeout(context.Background(), 45*time.Second) + defer cancel() + ctx := context.WithValue(ctxTimeout, "worker", w) codec := stratum.NewDefaultServerCodecContext(ctx, w.Conn()) w.codec = codec.(*stratum.DefaultServerCodec) @@ -75,7 +77,10 @@ func (w *Worker) Proxy() *proxy.Proxy { } func (w *Worker) Disconnect() { - w.Conn().Close() + if w.Conn() != nil { + w.Conn().Close() + } + if w.p != nil { w.p.Remove(w) w.p = nil