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:
nabbar
2023-04-11 14:41:07 +02:00
parent bd04ad86e6
commit c86e1dc1b5
6 changed files with 159 additions and 39 deletions

View File

@@ -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
}
}

View File

@@ -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() {

View File

@@ -29,7 +29,7 @@ package types
import "time"
const (
TimeoutWaitingPortFreeing = 100 * time.Microsecond
TimeoutWaitingPortFreeing = 250 * time.Microsecond
TimeoutWaitingStop = 5 * time.Second
BadHandlerName = "no handler"
)