Skip to content

Commit 0194e0d

Browse files
authored
Merge pull request #52 from guggero/stream-no-trailers-error
Fix "server closed the stream without sending trailers" error
2 parents 6681f7a + e583f54 commit 0194e0d

13 files changed

+419
-369
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
22

33
go:
4-
- "1.13.x"
4+
- "1.16.x"
55

66
cache:
77
directories:

aperture.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"sync"
1212
"time"
1313

14-
"github.com/coreos/etcd/clientv3"
1514
"github.com/lightninglabs/aperture/auth"
1615
"github.com/lightninglabs/aperture/mint"
1716
"github.com/lightninglabs/aperture/proxy"
@@ -20,6 +19,7 @@ import (
2019
"github.com/lightningnetwork/lnd/lnrpc"
2120
"github.com/lightningnetwork/lnd/signal"
2221
"github.com/lightningnetwork/lnd/tor"
22+
"go.etcd.io/etcd/clientv3"
2323
"golang.org/x/crypto/acme/autocert"
2424
"golang.org/x/net/http2"
2525
"golang.org/x/net/http2/h2c"
@@ -342,7 +342,7 @@ func getTLSConfig(serverName string, autoCert bool) (*tls.Config, error) {
342342
log.Infof("Generating TLS certificates...")
343343
err := cert.GenCertPair(
344344
selfSignedCertOrganization, tlsCertFile, tlsKeyFile,
345-
nil, nil, selfSignedCertValidity,
345+
nil, nil, false, selfSignedCertValidity,
346346
)
347347
if err != nil {
348348
return nil, err
@@ -389,7 +389,7 @@ func getTLSConfig(serverName string, autoCert bool) (*tls.Config, error) {
389389
log.Infof("Renewing TLS certificates...")
390390
err = cert.GenCertPair(
391391
selfSignedCertOrganization, tlsCertFile, tlsKeyFile,
392-
nil, nil, selfSignedCertValidity,
392+
nil, nil, false, selfSignedCertValidity,
393393
)
394394
if err != nil {
395395
return nil, err

go.mod

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
module github.com/lightninglabs/aperture
22

3-
go 1.13
3+
go 1.15
44

55
require (
6-
github.com/btcsuite/btcd v0.20.1-beta.0.20200730232343-1db1b6f8217f
6+
github.com/btcsuite/btcd v0.21.0-beta.0.20201208033208-6bd4c64a54fa
77
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
88
github.com/btcsuite/btcutil v1.0.2
99
github.com/btcsuite/btcwallet/wtxmgr v1.2.0
10-
github.com/coreos/etcd v3.3.22+incompatible
1110
github.com/fortytw2/leaktest v1.3.0
12-
github.com/golang/protobuf v1.3.2
11+
github.com/golang/protobuf v1.4.3
1312
github.com/jonboulle/clockwork v0.2.0 // indirect
1413
github.com/json-iterator/go v1.1.10 // indirect
15-
github.com/lightninglabs/lndclient v0.11.0-4
16-
github.com/lightningnetwork/lnd v0.11.1-beta
17-
github.com/lightningnetwork/lnd/cert v1.0.2
14+
github.com/lightninglabs/lndclient v0.12.0-4
15+
github.com/lightningnetwork/lnd v0.12.1-beta
16+
github.com/lightningnetwork/lnd/cert v1.0.3
1817
github.com/stretchr/testify v1.5.1
1918
github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect
19+
go.etcd.io/etcd v3.4.14+incompatible
2020
go.uber.org/zap v1.15.0 // indirect
2121
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
22-
golang.org/x/net v0.0.0-20191112182307-2180aed22343
23-
google.golang.org/grpc v1.25.1
22+
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7
23+
google.golang.org/grpc v1.29.1
2424
gopkg.in/macaroon.v2 v2.1.0
2525
gopkg.in/yaml.v2 v2.2.8
2626
sigs.k8s.io/yaml v1.2.0 // indirect
2727
)
28+
29+
// Fix incompatibility of etcd go.mod package.
30+
// See https://github.com/etcd-io/etcd/issues/11154
31+
replace go.etcd.io/etcd => go.etcd.io/etcd v0.5.0-alpha.5.0.20201125193152-8a03d2e9614b

go.sum

Lines changed: 102 additions & 64 deletions
Large diffs are not rendered by default.

internal/test/router_mock.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
type mockRouter struct {
10+
lndclient.RouterClient
1011
lnd *LndMockServices
1112
}
1213

onion_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/coreos/etcd/clientv3"
98
"github.com/lightningnetwork/lnd/tor"
9+
"go.etcd.io/etcd/clientv3"
1010
)
1111

1212
const (

proxy/proxy.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const (
2424
// "GET /availability/v1/btc.json HTTP/1.1" "" "Mozilla/5.0 ..."
2525
formatPattern = "- - \"%s %s %s\" \"%s\" \"%s\""
2626
hdrContentType = "Content-Type"
27+
hdrGrpcStatus = "Grpc-Status"
28+
hdrGrpcMessage = "Grpc-Message"
2729
hdrTypeGrpc = "application/grpc"
2830
)
2931

@@ -170,7 +172,7 @@ func (p *Proxy) UpdateServices(services []*Service) error {
170172

171173
p.proxyBackend = &httputil.ReverseProxy{
172174
Director: p.director,
173-
Transport: transport,
175+
Transport: &trailerFixingTransport{next: transport},
174176
ModifyResponse: func(res *http.Response) error {
175177
addCorsHeaders(res.Header)
176178
return nil
@@ -329,11 +331,42 @@ func sendDirectResponse(w http.ResponseWriter, r *http.Request,
329331
// so we can use that.
330332
switch {
331333
case strings.HasPrefix(r.Header.Get(hdrContentType), hdrTypeGrpc):
332-
w.Header().Set("Grpc-Status", strconv.Itoa(int(codes.Internal)))
333-
w.Header().Set("Grpc-Message", errInfo)
334+
w.Header().Set(hdrGrpcStatus, strconv.Itoa(int(codes.Internal)))
335+
w.Header().Set(hdrGrpcMessage, errInfo)
336+
w.Header().Set("Content-Length", "0")
337+
w.Header().Set(":status", strconv.Itoa(statusCode))
338+
w.Header().Add("Trailer", hdrGrpcStatus)
339+
w.Header().Add("Trailer", hdrGrpcMessage)
340+
334341
w.WriteHeader(statusCode)
335342

336343
default:
337344
http.Error(w, errInfo, statusCode)
338345
}
339346
}
347+
348+
type trailerFixingTransport struct {
349+
next http.RoundTripper
350+
}
351+
352+
// RoundTrip is a transport round tripper implementation that fixes an issue
353+
// in the official httputil.ReverseProxy implementation. Apparently the HTTP/2
354+
// trailers aren't properly forwarded in some cases. We fix this by always
355+
// copying the Grpc-Status and Grpc-Message fields to the trailers, as those are
356+
// usually expected to be in the trailer fields.
357+
// Inspired by https://github.com/elazarl/goproxy/issues/408.
358+
func (l *trailerFixingTransport) RoundTrip(req *http.Request) (*http.Response,
359+
error) {
360+
361+
resp, err := l.next.RoundTrip(req)
362+
if resp != nil && len(resp.Trailer) == 0 {
363+
if len(resp.Header.Values(hdrGrpcStatus)) > 0 {
364+
resp.Trailer = make(http.Header)
365+
grpcStatus := resp.Header.Get(hdrGrpcStatus)
366+
grpcMessage := resp.Header.Get(hdrGrpcMessage)
367+
resp.Trailer.Add(hdrGrpcStatus, grpcStatus)
368+
resp.Trailer.Add(hdrGrpcMessage, grpcMessage)
369+
}
370+
}
371+
return resp, err
372+
}

0 commit comments

Comments
 (0)