Skip to content

Commit

Permalink
Swap closing order in inAxfr and inIxfr (#1511)
Browse files Browse the repository at this point in the history
* Fix closing order

* Comment to make clear that the close order is deliberate

---------

Co-authored-by: Tim Scheuermann <tscheuermann@anexia-it.com>
  • Loading branch information
noxer and Tim Scheuermann authored Nov 13, 2023
1 parent 5d3f81b commit 3d593a6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions xfr.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) {

func (t *Transfer) inAxfr(q *Msg, c chan *Envelope) {
first := true
defer t.Close()
defer close(c)
defer func() {
// First close the connection, then the channel. This allows functions blocked on
// the channel to assume that the connection is closed and no further operations are
// pending when they resume.
t.Close()
close(c)
}()
timeout := dnsTimeout
if t.ReadTimeout != 0 {
timeout = t.ReadTimeout
Expand Down Expand Up @@ -131,8 +136,13 @@ func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) {
axfr := true
n := 0
qser := q.Ns[0].(*SOA).Serial
defer t.Close()
defer close(c)
defer func() {
// First close the connection, then the channel. This allows functions blocked on
// the channel to assume that the connection is closed and no further operations are
// pending when they resume.
t.Close()
close(c)
}()
timeout := dnsTimeout
if t.ReadTimeout != 0 {
timeout = t.ReadTimeout
Expand Down

0 comments on commit 3d593a6

Please sign in to comment.