mirror of
https://github.com/nabbar/golib.git
synced 2025-09-27 04:06:05 +08:00
Package httpserver:
- fix bug with context deadline Package Database: - fix darwin/arm64 import C for gorm/sqlite (using shared lib sqlite) Bump dependencies
This commit is contained in:
@@ -57,7 +57,7 @@ func (o *srv) HealthCheck(ctx context.Context) error {
|
||||
} else if e = o.r.ErrorsLast(); e != nil {
|
||||
return e
|
||||
} else {
|
||||
return errNotRunning
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,8 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
srvtps "github.com/nabbar/golib/httpserver/types"
|
||||
@@ -188,17 +190,27 @@ func (o *srv) PortInUse(ctx context.Context, listen string) liberr.Error {
|
||||
}
|
||||
}()
|
||||
|
||||
ctx, cnl = context.WithTimeout(ctx, srvtps.TimeoutWaitingPortFreeing)
|
||||
con, err = dia.DialContext(ctx, "tcp", listen)
|
||||
if strings.Contains(listen, ":") {
|
||||
uri := &url.URL{
|
||||
Host: listen,
|
||||
}
|
||||
|
||||
if con != nil {
|
||||
_ = con.Close()
|
||||
con = nil
|
||||
if h := uri.Hostname(); h == "0.0.0.0" || h == "::1" {
|
||||
listen = "127.0.0.1:" + uri.Port()
|
||||
}
|
||||
}
|
||||
|
||||
cnl()
|
||||
cnl = nil
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
ctx, cnl = context.WithTimeout(ctx, srvtps.TimeoutWaitingPortFreeing)
|
||||
defer cnl()
|
||||
}
|
||||
|
||||
con, err = dia.DialContext(ctx, "tcp", listen)
|
||||
defer func() {
|
||||
if con != nil {
|
||||
_ = con.Close()
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -215,8 +227,20 @@ func (o *srv) PortNotUse(ctx context.Context, listen string) error {
|
||||
dia = net.Dialer{}
|
||||
)
|
||||
|
||||
ctx, cnl = context.WithTimeout(context.TODO(), srvtps.TimeoutWaitingPortFreeing)
|
||||
defer cnl()
|
||||
if strings.Contains(listen, ":") {
|
||||
uri := &url.URL{
|
||||
Host: listen,
|
||||
}
|
||||
|
||||
if h := uri.Hostname(); h == "0.0.0.0" || h == "::1" {
|
||||
listen = "127.0.0.1:" + uri.Port()
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
ctx, cnl = context.WithTimeout(ctx, srvtps.TimeoutWaitingPortFreeing)
|
||||
defer cnl()
|
||||
}
|
||||
|
||||
con, err = dia.DialContext(ctx, "tcp", listen)
|
||||
defer func() {
|
||||
|
@@ -29,7 +29,7 @@ package types
|
||||
import "time"
|
||||
|
||||
const (
|
||||
TimeoutWaitingPortFreeing = 100 * time.Microsecond
|
||||
TimeoutWaitingPortFreeing = 250 * time.Microsecond
|
||||
TimeoutWaitingStop = 5 * time.Second
|
||||
BadHandlerName = "no handler"
|
||||
)
|
||||
|
Reference in New Issue
Block a user