Skip to content

Commit b0bda95

Browse files
committed
revert: ReadWrite to ReadWriteCloser
Signed-off-by: Johannes Großmann <grossmann.johannes@t-online.de>
1 parent 593d012 commit b0bda95

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

plugin/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func Test_newCfgForManualLaunch(t *testing.T) {
114114
// as in the context of where this function is used we don't care.
115115
func runUncheckedDummyAcceptor(logger logging.Logger, listener net.Listener) {
116116
httpMux := http.NewServeMux()
117-
httpMux.Handle(ipc.NewHijackAcceptor(logger, func(context.Context, io.ReadWriter) {}))
117+
httpMux.Handle(ipc.NewHijackAcceptor(logger, func(context.Context, io.ReadWriteCloser) {}))
118118
server := &http.Server{Handler: httpMux}
119119
go func() {
120120
_ = server.Serve(listener)

x/ipc/hijack.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type CloseWriter interface {
9595
}
9696

9797
type hijackHandler struct {
98-
cb func(ctx context.Context, rw io.ReadWriter)
98+
cb func(ctx context.Context, conn io.ReadWriteCloser)
9999
ackTimeout time.Duration
100100
logger logging.Logger
101101
}
@@ -131,7 +131,7 @@ func (h *hijackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
131131
return
132132
}
133133

134-
defer conn.Close()
134+
defer func() { _ = conn.Close() }() // Might have already been called inside the callback -> ignore double close error
135135

136136
done := make(chan struct{})
137137
go func() {
@@ -153,7 +153,8 @@ func (h *hijackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
153153
return
154154
}
155155

156-
// Important: The server still owns net.Conn! When this handler returns, conn gets closed.
156+
// The server still owns net.Conn. When this handler returns, conn gets closed.
157+
// However, the callback might have to call Close() to abort/unblock any pending/blocking Read().
157158
h.cb(r.Context(), conn)
158159
}()
159160

@@ -163,6 +164,6 @@ func (h *hijackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
163164
}
164165
}
165166

166-
func NewHijackAcceptor(logger logging.Logger, cb func(context.Context, io.ReadWriter)) (string, http.Handler) {
167+
func NewHijackAcceptor(logger logging.Logger, cb func(context.Context, io.ReadWriteCloser)) (string, http.Handler) {
167168
return hijackPath, &hijackHandler{logger: logger, cb: cb, ackTimeout: hijackTimeout}
168169
}

x/ipc/hijack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func Test_hijacking(t *testing.T) {
4343
wait := make(chan struct{})
4444
once := sync.OnceFunc(func() { close(wait) })
4545
defer once()
46-
httpMux.Handle(NewHijackAcceptor(testhelper.TestLogger(t), func(_ context.Context, closer io.ReadWriter) {
46+
httpMux.Handle(NewHijackAcceptor(testhelper.TestLogger(t), func(_ context.Context, closer io.ReadWriteCloser) {
4747
ch <- closer
4848
<-wait
4949
}))

0 commit comments

Comments
 (0)