Skip to content

Commit 961783a

Browse files
authored
Merge pull request #3782 from openziti/backport-ert-close
[Backport-1.6] Fix ER/T half-close logic. Fixes #3781
2 parents acc51c9 + f5621c3 commit 961783a

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Release 1.6.16
2+
3+
## What's New
4+
5+
* Bug fixes and dependency updates
6+
7+
## Component Updates and Bug Fixes
8+
9+
* github.com/openziti/ziti: [v1.6.15 -> v1.6.16](https://github.com/openziti/ziti/compare/v1.6.15...v1.6.16)
10+
* [Issue #3781](https://github.com/openziti/ziti/issues/3781) - [Backport-1.6] ER/T half-close logic is incorrect
11+
12+
113
# Release 1.6.15
214

315
## What's New

router/xgress_common/connection.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ func (self *XgressConn) ReadPayload() ([]byte, map[uint8][]byte, error) {
205205
if self.IsClosed() {
206206
return nil, nil, xgress.ErrPeerClosed
207207
}
208-
209-
if self.IsWriteClosed() {
210-
<-self.writeDone
211-
return nil, nil, xgress.ErrPeerClosed
212-
}
213208
}
214209

215210
buffer := make([]byte, self.bufferSize)
@@ -241,17 +236,20 @@ func (self *XgressConn) ReadPayload() ([]byte, map[uint8][]byte, error) {
241236
}
242237

243238
if err != nil && n == 0 && errors.Is(err, io.EOF) {
244-
if connAliveErr := self.Conn.SetWriteDeadline(time.Time{}); connAliveErr == nil {
239+
if connAliveErr := self.Conn.SetWriteDeadline(time.Time{}); connAliveErr != nil {
245240
self.flags.Set(closedFlag, true)
246-
pfxlog.Logger().WithError(connAliveErr).Errorf("failed to set write deadline, connection is fully closed")
241+
pfxlog.Logger().WithError(connAliveErr).Debug("failed to set write deadline, connection is fully closed")
242+
return nil, nil, xgress.ErrPeerClosed
247243
}
248244

249245
if self.flags.IsSet(halfCloseFlag) {
246+
// first send the fin headers
250247
if self.flags.CompareAndSet(sentFinFlag, false, true) {
251248
return nil, GetFinHeaders(), nil
252-
} else {
253-
return nil, nil, xgress.ErrPeerClosed
254249
}
250+
251+
// next time return EOF
252+
return nil, nil, io.EOF
255253
}
256254
}
257255

tests/tunneler_data_flow_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@ func Test_TunnelerDataflowUdp(t *testing.T) {
333333
l, err := net.ListenPacket("udp", "localhost:8690")
334334
ctx.Req.NoError(err)
335335

336-
time.Sleep(time.Second)
337-
338336
errC := make(chan error, 10)
339337
go echoData(l, errC)
340338

@@ -350,6 +348,25 @@ func Test_TunnelerDataflowUdp(t *testing.T) {
350348
counter++
351349
}
352350

351+
// The first iteration acts as a readiness poll. The tunneler's UDP intercept
352+
// proxy on port 8688 may not be listening yet, so retry with a longer timeout
353+
// until we get a successful round-trip.
354+
if i == 0 {
355+
deadline := time.Now().Add(30 * time.Second)
356+
for {
357+
ctx.Req.NoError(conn.SetDeadline(time.Now().Add(time.Second)))
358+
_, _ = conn.Write(buf)
359+
readBuf := make([]byte, size)
360+
_, readErr := io.ReadFull(conn, readBuf)
361+
if readErr == nil {
362+
ctx.Req.Equal(buf, readBuf)
363+
break
364+
}
365+
ctx.Req.True(time.Now().Before(deadline), "timed out waiting for UDP proxy to be ready")
366+
}
367+
continue
368+
}
369+
353370
time.Sleep(time.Millisecond)
354371

355372
err := conn.SetDeadline(time.Now().Add(time.Second))

0 commit comments

Comments
 (0)