Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
swordlet committed Aug 12, 2023
1 parent 0d1f8a3 commit 988f52a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

var (
version = "2.0.2"
version = "2.0.3"

// cmd line options
configFile *string
Expand Down
21 changes: 14 additions & 7 deletions server/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/tcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
9 changes: 7 additions & 2 deletions server/tcp/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 988f52a

Please sign in to comment.