@@ -34,6 +34,8 @@ import (
34
34
kerrors "github.com/go-kratos/kratos/v2/errors"
35
35
"github.com/go-kratos/kratos/v2/log"
36
36
"google.golang.org/genproto/googleapis/bytestream"
37
+ "google.golang.org/grpc/codes"
38
+ "google.golang.org/grpc/status"
37
39
)
38
40
39
41
// Implements the bytestream interface
@@ -109,7 +111,7 @@ func (s *ByteStreamService) Write(stream bytestream.ByteStream_WriteServer) erro
109
111
110
112
// Now it's time to check if the data provider has sent an error
111
113
if err != nil {
112
- if errors .Is (err , context .Canceled ) {
114
+ if errors .Is (err , context .Canceled ) || status . Code ( err ) == codes . Canceled {
113
115
s .log .Infow ("msg" , "upload canceled" , "digest" , req .resource .Digest , "name" , req .resource .FileName )
114
116
return nil
115
117
}
@@ -192,11 +194,16 @@ func bufferStream(ctx context.Context, stream bytestream.ByteStream_WriteServer,
192
194
default :
193
195
// Extract the next chunk of data from the stream request
194
196
req , err := getWriteRequest (stream )
195
- // There is nothing else to read or the client has marked the upload as finished
196
- if errors .Is (err , io .EOF ) || req .GetFinishWrite () {
197
+ if err != nil {
198
+ // If we have finished reading the stream we don't consider it a real error
199
+ if ! errors .Is (err , io .EOF ) {
200
+ bufferErr = err
201
+ }
197
202
return
198
- } else if err != nil { // If there is any other error we return it
199
- bufferErr = err
203
+ }
204
+
205
+ // Check if the client has finished sending data
206
+ if req .GetFinishWrite () {
200
207
return
201
208
}
202
209
0 commit comments