Skip to content

Commit a52ebc8

Browse files
committed
module: Break dependency cycles when loading config correctly
See #832
1 parent da6bcb1 commit a52ebc8

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

framework/module/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ func (r *Registry) ensureInitialized(name string, entry *registryEntry) error {
105105

106106
r.logger.DebugMsg("module configure",
107107
"mod_name", entry.Mod.Name(), "inst_name", entry.Mod.InstanceName())
108+
r.initialized[name] = struct{}{}
108109
err := entry.LazyInit()
109110
if err != nil {
110111
return err
111112
}
112-
r.initialized[name] = struct{}{}
113113

114114
return nil
115115
}

tests/modules_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//go:build integration
2+
3+
/*
4+
Maddy Mail Server - Composable all-in-one email server.
5+
Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package tests_test
22+
23+
import (
24+
"testing"
25+
26+
"github.com/foxcpp/maddy/tests"
27+
)
28+
29+
func TestConfigCycle(tt *testing.T) {
30+
tt.Parallel()
31+
32+
t := tests.NewT(tt)
33+
t.DNS(nil)
34+
t.Config(`
35+
hostname mx.maddy.test
36+
37+
msgpipeline local_routing {
38+
destination maddy.test {
39+
deliver_to dummy
40+
}
41+
default_destination {
42+
deliver_to &outbound_queue
43+
}
44+
}
45+
46+
target.queue outbound_queue {
47+
target dummy
48+
autogenerated_msg_domain maddy.test
49+
bounce {
50+
deliver_to &local_routing
51+
}
52+
}
53+
54+
smtp tcp://127.0.0.1:1443 {
55+
tls off
56+
57+
deliver_to &local_routing
58+
}
59+
`)
60+
t.Run(1)
61+
62+
t.Close()
63+
}

0 commit comments

Comments
 (0)