Commit 8b25617f authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/zeo: Close networkers

xnet.Networker added Close recently and is now required to be explicitly
closed by the user:

kirr/go123@01a77bb9
parent 3f12d2a5
...@@ -406,6 +406,11 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb ...@@ -406,6 +406,11 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb
net = xnet.NetPlain("unix") net = xnet.NetPlain("unix")
addr = u.Path addr = u.Path
} }
defer func() {
if net != nil {
net.Close()
}
}()
storageID := "1" storageID := "1"
...@@ -422,6 +427,8 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb ...@@ -422,6 +427,8 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb
if err != nil { if err != nil {
return nil, zodb.InvalidTid, err return nil, zodb.InvalidTid, err
} }
zlink.closeq = append(zlink.closeq, net)
net = nil
defer func() { defer func() {
if err != nil { if err != nil {
......
...@@ -230,6 +230,9 @@ func TestHandshake(t *testing.T) { ...@@ -230,6 +230,9 @@ func TestHandshake(t *testing.T) {
withZEOSrv(t, func(t *testing.T, zsrv ZEOSrv) { withZEOSrv(t, func(t *testing.T, zsrv ZEOSrv) {
ctx := context.Background() ctx := context.Background()
net := xnet.NetPlain("unix") net := xnet.NetPlain("unix")
defer func() {
err := net.Close(); X(err)
}()
zlink, err := dialZLink(ctx, net, zsrv.Addr()); X(err) zlink, err := dialZLink(ctx, net, zsrv.Addr()); X(err)
defer func() { defer func() {
err := zlink.Close(); X(err) err := zlink.Close(); X(err)
......
...@@ -80,6 +80,8 @@ type zLink struct { ...@@ -80,6 +80,8 @@ type zLink struct {
ver string // protocol version in use (without "Z" or "M" prefix) ver string // protocol version in use (without "Z" or "M" prefix)
enc encoding // protocol encoding in use ('Z' or 'M') enc encoding // protocol encoding in use ('Z' or 'M')
closeq []io.Closer // to be also closed on Close
} }
// zLinkError is returned by zLink operations. // zLinkError is returned by zLink operations.
...@@ -128,6 +130,12 @@ func (zl *zLink) shutdown(err error) { ...@@ -128,6 +130,12 @@ func (zl *zLink) shutdown(err error) {
if err == nil { if err == nil {
err = err2 err = err2
} }
for _, c := range(zl.closeq) {
err2 := c.Close()
if err == nil {
err = err2
}
}
if err != nil { if err != nil {
log.Printf("%s", err) log.Printf("%s", err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment