Skip to content

Commit 827de14

Browse files
committed
[FIXED] Use default timeout for ObjectStore.Get when no deadline is set on ctx
Signed-off-by: Piotr Piotrowski <[email protected]>
1 parent 8a2bd73 commit 827de14

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

jetstream/object.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ const (
488488
)
489489

490490
func (js *jetStream) CreateObjectStore(ctx context.Context, cfg ObjectStoreConfig) (ObjectStore, error) {
491-
scfg, err := js.prepareObjectStoreConfig(ctx, cfg)
491+
scfg, err := js.prepareObjectStoreConfig(cfg)
492492
if err != nil {
493493
return nil, err
494494
}
@@ -511,7 +511,7 @@ func (js *jetStream) CreateObjectStore(ctx context.Context, cfg ObjectStoreConfi
511511
}
512512

513513
func (js *jetStream) UpdateObjectStore(ctx context.Context, cfg ObjectStoreConfig) (ObjectStore, error) {
514-
scfg, err := js.prepareObjectStoreConfig(ctx, cfg)
514+
scfg, err := js.prepareObjectStoreConfig(cfg)
515515
if err != nil {
516516
return nil, err
517517
}
@@ -533,7 +533,7 @@ func (js *jetStream) UpdateObjectStore(ctx context.Context, cfg ObjectStoreConfi
533533
}
534534

535535
func (js *jetStream) CreateOrUpdateObjectStore(ctx context.Context, cfg ObjectStoreConfig) (ObjectStore, error) {
536-
scfg, err := js.prepareObjectStoreConfig(ctx, cfg)
536+
scfg, err := js.prepareObjectStoreConfig(cfg)
537537
if err != nil {
538538
return nil, err
539539
}
@@ -550,7 +550,7 @@ func (js *jetStream) CreateOrUpdateObjectStore(ctx context.Context, cfg ObjectSt
550550
return mapStreamToObjectStore(js, pushJS, cfg.Bucket, stream), nil
551551
}
552552

553-
func (js *jetStream) prepareObjectStoreConfig(ctx context.Context, cfg ObjectStoreConfig) (StreamConfig, error) {
553+
func (js *jetStream) prepareObjectStoreConfig(cfg ObjectStoreConfig) (StreamConfig, error) {
554554
if !validBucketRe.MatchString(cfg.Bucket) {
555555
return StreamConfig{}, ErrInvalidStoreName
556556
}
@@ -824,6 +824,7 @@ func (info *ObjectInfo) isLink() bool {
824824

825825
// Get will pull the object from the underlying stream.
826826
func (obs *obs) Get(ctx context.Context, name string, opts ...GetObjectOpt) (ObjectResult, error) {
827+
ctx, cancel := obs.js.wrapContextWithoutDeadline(ctx)
827828
var o getObjectOpts
828829
for _, opt := range opts {
829830
if opt != nil {
@@ -933,10 +934,15 @@ func (obs *obs) Get(ctx context.Context, name string, opts ...GetObjectOpt) (Obj
933934
nats.Context(ctx),
934935
nats.BindStream(streamName),
935936
}
936-
_, err = obs.pushJS.Subscribe(chunkSubj, processChunk, subscribeOpts...)
937+
sub, err := obs.pushJS.Subscribe(chunkSubj, processChunk, subscribeOpts...)
937938
if err != nil {
938939
return nil, err
939940
}
941+
sub.SetClosedHandler(func(subject string) {
942+
if cancel != nil {
943+
cancel()
944+
}
945+
})
940946

941947
return result, nil
942948
}

0 commit comments

Comments
 (0)