update for latest micro
All checks were successful
test / test (push) Successful in 1m58s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2025-01-15 13:06:43 +03:00
parent 4470cb69a2
commit cd84ab56af

18
tcp.go
View File

@ -1,5 +1,5 @@
// Package tcp implements a go-micro.Server // Package tcp implements a go-micro.Server
package tcp // import "go.unistack.org/micro-server-tcp/v3" package tcp
import ( import (
"context" "context"
@ -16,7 +16,7 @@ import (
"go.unistack.org/micro/v3/logger" "go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/register" "go.unistack.org/micro/v3/register"
"go.unistack.org/micro/v3/server" "go.unistack.org/micro/v3/server"
msync "go.unistack.org/micro/v3/sync"
"golang.org/x/net/netutil" "golang.org/x/net/netutil"
) )
@ -62,6 +62,9 @@ func (h *Server) Options() server.Options {
} }
func (h *Server) Init(opts ...server.Option) error { func (h *Server) Init(opts ...server.Option) error {
if h.opts.Wait == nil {
h.opts.Wait = msync.NewWaitGroup()
}
if len(opts) == 0 && h.init { if len(opts) == 0 && h.init {
return nil return nil
} }
@ -486,15 +489,14 @@ func (h *Server) serve(ln net.Listener, hd Handler) {
return return
} }
if err != nil { if h.opts.Wait != nil {
config.Logger.Error(config.Context, "tcp: accept err", err) h.opts.Wait.Add(1)
return
} }
h.opts.Wait.Add(1)
go func() { go func() {
hd.Serve(c) hd.Serve(c)
h.opts.Wait.Done() if h.opts.Wait != nil {
h.opts.Wait.Done()
}
}() }()
} }
} }