@@ -192,13 +192,9 @@ func (r *streamResult) nextPart(ctx context.Context) (
192192 case <- r .closed :
193193 return nil , xerrors .WithStackTrace (io .EOF )
194194 default :
195- if r .stream == nil {
196- return nil , xerrors .WithStackTrace (io .EOF )
197- }
198-
199195 part , err = nextPart (r .stream )
200196 if err != nil {
201- r .stream = nil
197+ r .closeOnce ()
202198
203199 for _ , callback := range r .onNextPartErr {
204200 callback (err )
@@ -245,15 +241,16 @@ func (r *streamResult) Close(ctx context.Context) (finalErr error) {
245241 case <- ctx .Done ():
246242 return xerrors .WithStackTrace (ctx .Err ())
247243 case <- r .closed :
248- return xerrors . WithStackTrace ( errStreamResultClosed )
244+ return nil
249245 default :
250- _ , err := r . nextPart ( ctx )
251- if err != nil {
252- if xerrors .Is (err , io .EOF ) {
253- return nil
254- }
246+ if r . stream != nil {
247+ if _ , err := r . nextPart ( ctx ); err != nil {
248+ if xerrors .Is (err , io .EOF ) {
249+ return nil
250+ }
255251
256- return xerrors .WithStackTrace (err )
252+ return xerrors .WithStackTrace (err )
253+ }
257254 }
258255 }
259256 }
@@ -284,7 +281,7 @@ func (r *streamResult) nextResultSet(ctx context.Context) (_ *resultSet, err err
284281 r .statsCallback (stats .FromQueryStats (part .GetExecStats ()))
285282 }
286283 if part .GetResultSetIndex () < r .resultSetIndex {
287- r .stream = nil
284+ r .closeOnce ()
288285
289286 if part .GetResultSetIndex () <= 0 && r .resultSetIndex > 0 {
290287 return nil , xerrors .WithStackTrace (io .EOF )
0 commit comments