Skip to content

Commit 3d593a6

Browse files
noxerTim Scheuermann
andauthored
Swap closing order in inAxfr and inIxfr (#1511)
* Fix closing order * Comment to make clear that the close order is deliberate --------- Co-authored-by: Tim Scheuermann <[email protected]>
1 parent 5d3f81b commit 3d593a6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

xfr.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) {
8080

8181
func (t *Transfer) inAxfr(q *Msg, c chan *Envelope) {
8282
first := true
83-
defer t.Close()
84-
defer close(c)
83+
defer func() {
84+
// First close the connection, then the channel. This allows functions blocked on
85+
// the channel to assume that the connection is closed and no further operations are
86+
// pending when they resume.
87+
t.Close()
88+
close(c)
89+
}()
8590
timeout := dnsTimeout
8691
if t.ReadTimeout != 0 {
8792
timeout = t.ReadTimeout
@@ -131,8 +136,13 @@ func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) {
131136
axfr := true
132137
n := 0
133138
qser := q.Ns[0].(*SOA).Serial
134-
defer t.Close()
135-
defer close(c)
139+
defer func() {
140+
// First close the connection, then the channel. This allows functions blocked on
141+
// the channel to assume that the connection is closed and no further operations are
142+
// pending when they resume.
143+
t.Close()
144+
close(c)
145+
}()
136146
timeout := dnsTimeout
137147
if t.ReadTimeout != 0 {
138148
timeout = t.ReadTimeout

0 commit comments

Comments
 (0)