Skip to content

Commit 9c8e1e2

Browse files
committed
Merge branch 'master' into dev
2 parents ea5a4e7 + 58e8a11 commit 9c8e1e2

11 files changed

Lines changed: 59 additions & 13 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
id: docker
145145
with:
146146
context: .
147-
platforms: linux/amd64 #,linux/arm64 Temporary disabled due to SIGSEGV in gcc.
147+
platforms: linux/amd64,linux/arm64
148148
file: Dockerfile
149149
push: true
150150
tags: ${{ steps.meta.outputs.tags }}

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.4
1+
0.9.5

framework/log/log.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ func (l *Logger) Write(s []byte) (int, error) {
205205
return len(s), nil
206206
}
207207

208+
// Close closes underlying output in Out.
209+
func (l *Logger) Close() error {
210+
if l.Out == nil {
211+
return nil
212+
}
213+
214+
return l.Out.Close()
215+
}
216+
208217
// DebugWriter returns a writer that will act like Logger.Write
209218
// but will use debug flag on messages. If Logger.Debug is false,
210219
// Write method of returned object will be no-op.

internal/endpoint/smtp/smtp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (endp *Endpoint) setConfig(cfg *config.Map) error {
274274
cfg.Bool("defer_sender_reject", false, true, &endp.deferServerReject)
275275
cfg.Int("max_logged_rcpt_errors", false, false, 5, &endp.maxLoggedRcptErrors)
276276
cfg.Custom("limits", false, false, func() (interface{}, error) {
277-
return &limits.Group{}, nil
277+
return limits.Empty(endp.log.Sublogger("limits")), nil
278278
}, func(cfg *config.Map, n config.Node) (interface{}, error) {
279279
var g *limits.Group
280280
if err := modconfig.GroupFromNode("limits", n.Args, n, cfg.Globals, &g); err != nil {

internal/limits/limits.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ package limits
2828

2929
import (
3030
"context"
31+
"fmt"
3132
"net"
3233
"strconv"
3334
"time"
3435

3536
"github.com/foxcpp/maddy/framework/config"
3637
"github.com/foxcpp/maddy/framework/container"
38+
"github.com/foxcpp/maddy/framework/log"
3739
"github.com/foxcpp/maddy/framework/module"
3840
"github.com/foxcpp/maddy/framework/module/modules"
3941
"github.com/foxcpp/maddy/internal/limits/limiters"
4042
)
4143

4244
type Group struct {
45+
log *log.Logger
4346
instName string
4447

4548
global limiters.MultiLimit
@@ -48,8 +51,15 @@ type Group struct {
4851
dest *limiters.BucketSet // BucketSet of MultiLimit
4952
}
5053

54+
func Empty(log *log.Logger) *Group {
55+
return &Group{
56+
log: log,
57+
}
58+
}
59+
5160
func New(c *container.C, _, instName string) (module.Module, error) {
5261
return &Group{
62+
log: c.DefaultLogger.Sublogger("limits"),
5363
instName: instName,
5464
}, nil
5565
}
@@ -177,22 +187,28 @@ func (g *Group) TakeMsg(ctx context.Context, addr net.IP, sourceDomain string) e
177187
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
178188
defer cancel()
179189

190+
g.log.DebugMsg("global TakeContext")
180191
if err := g.global.TakeContext(ctx); err != nil {
181-
return err
192+
return fmt.Errorf("TakeMsg: global: %w", err)
182193
}
194+
g.log.DebugMsg("global TakeContext done")
183195

184196
if g.ip != nil {
197+
g.log.DebugMsg("ip TakeContext", "ip", addr.String())
185198
if err := g.ip.TakeContext(ctx, addr.String()); err != nil {
186199
g.global.Release()
187-
return err
200+
return fmt.Errorf("TakeMsg: ip: %w", err)
188201
}
202+
g.log.DebugMsg("ip TakeContext done", "ip", addr.String())
189203
}
190204
if g.source != nil {
205+
g.log.DebugMsg("source TakeContext", "domain", sourceDomain)
191206
if err := g.source.TakeContext(ctx, sourceDomain); err != nil {
192207
g.global.Release()
193208
g.ip.Release(addr.String())
194-
return err
209+
return fmt.Errorf("TakeMSg: source: %w", err)
195210
}
211+
g.log.DebugMsg("source TakeContext done", "domain", sourceDomain)
196212
}
197213
return nil
198214
}
@@ -201,17 +217,27 @@ func (g *Group) TakeDest(ctx context.Context, domain string) error {
201217
if g.dest == nil {
202218
return nil
203219
}
220+
204221
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
205222
defer cancel()
206-
return g.dest.TakeContext(ctx, domain)
223+
224+
g.log.DebugMsg("TakeDest", "domain", domain)
225+
if err := g.dest.TakeContext(ctx, domain); err != nil {
226+
return fmt.Errorf("TakeDest: dest: %w", err)
227+
}
228+
g.log.DebugMsg("TakeDest done", "domain", domain)
229+
return nil
207230
}
208231

209232
func (g *Group) ReleaseMsg(addr net.IP, sourceDomain string) {
233+
g.log.DebugMsg("global ReleaseMsg")
210234
g.global.Release()
211235
if g.ip != nil {
236+
g.log.DebugMsg("ip ReleaseMsg", "ip", addr.String())
212237
g.ip.Release(addr.String())
213238
}
214239
if g.source != nil {
240+
g.log.DebugMsg("source ReleaseMsg", "domain", sourceDomain)
215241
g.source.Release(sourceDomain)
216242
}
217243
}
@@ -220,7 +246,10 @@ func (g *Group) ReleaseDest(domain string) {
220246
if g.dest == nil {
221247
return
222248
}
249+
250+
g.log.DebugMsg("ReleaseDest", "domain", domain)
223251
g.dest.Release(domain)
252+
g.log.DebugMsg("ReleaseDest done", "domain", domain)
224253
}
225254

226255
func (g *Group) Name() string {

internal/msgpipeline/msgpipeline.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func New(globals map[string]interface{}, cfg []config.Node) (*MsgPipeline, error
9090
return &MsgPipeline{
9191
msgpipelineCfg: parsedCfg,
9292
Resolver: dns.DefaultResolver(),
93+
Log: log.DefaultLogger.Sublogger("msgpipeline"),
9394
}, err
9495
}
9596

internal/smtpconn/smtpconn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (c *C) attemptConnect(ctx context.Context, lmtp bool, endp config.Endpoint,
239239
conn, err = c.Dialer(dialCtx, endp.Network(), endp.Address())
240240
cancel()
241241
if err != nil {
242-
return false, nil, nil, err
242+
return false, nil, nil, fmt.Errorf("dialer: %w", err)
243243
}
244244

245245
if endp.IsTLS() {

internal/target/remote/connect.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type mxConn struct {
4545
errored bool
4646

4747
reuseLimit int
48+
takeDest bool
4849

4950
// Amount of times connection was used for an SMTP transaction.
5051
transactions int
@@ -207,6 +208,10 @@ func (rd *remoteDelivery) attemptMX(ctx context.Context, conn *mxConn, record *n
207208
}
208209

209210
func (rd *remoteDelivery) closeConn(c *mxConn) {
211+
if c.takeDest {
212+
rd.rt.limits.ReleaseDest(c.domain)
213+
}
214+
210215
if err := c.Close(); err != nil {
211216
rd.log.Error("client connection close failed", err)
212217
}
@@ -270,6 +275,7 @@ func (rd *remoteDelivery) connectionForDomain(ctx context.Context, domain string
270275
return nil, err
271276
}
272277
region.End()
278+
conn.takeDest = true
273279

274280
// Relaxed REQUIRETLS mode is not conforming to the specification strictly
275281
// but allows to start deploying client support for REQUIRETLS without the

internal/target/remote/remote.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (rt *Target) Configure(inlineArgs []string, cfg *config.Map) error {
130130
return p.L, nil
131131
}, &rt.policies)
132132
cfg.Custom("limits", false, false, func() (interface{}, error) {
133-
return &limits.Group{}, nil
133+
return limits.Empty(rt.log.Sublogger("limits")), nil
134134
}, func(cfg *config.Map, n config.Node) (interface{}, error) {
135135
var g *limits.Group
136136
if err := modconfig.GroupFromNode("limits", n.Args, n, cfg.Globals, &g); err != nil {
@@ -455,6 +455,7 @@ func (rd *remoteDelivery) Commit(ctx context.Context) error {
455455
func (rd *remoteDelivery) Close() error {
456456
for _, conn := range rd.connections {
457457
rd.rt.limits.ReleaseDest(conn.domain)
458+
conn.takeDest = false
458459
conn.transactions++
459460

460461
if !conn.Usable() {

internal/target/remote/remote_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func testTarget(t *testing.T, zones map[string]mockdns.Zone, extResolver *dns.Ex
6262
tlsConfig: &tls.Config{},
6363
log: testutils.Logger(t, "remote"),
6464
policies: extraPolicies,
65-
limits: &limits.Group{},
65+
limits: limits.Empty(testutils.Logger(t, "limits")),
6666
pool: pool.New(pool.Config{
6767
MaxKeys: 5000,
6868
MaxConnsPerKey: 5, // basically, max. amount of idle connections in cache

0 commit comments

Comments
 (0)