From 6bb0861eb7e866466b06db482b9ba15439343930 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Fri, 11 Feb 2022 10:45:09 +0100 Subject: [PATCH] avoid seg fault when stream restore fails Signed-off-by: R.I.Pienaar --- server/jetstream_cluster.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/jetstream_cluster.go b/server/jetstream_cluster.go index f5fa25c8..847d5a6b 100644 --- a/server/jetstream_cluster.go +++ b/server/jetstream_cluster.go @@ -3398,9 +3398,9 @@ type streamAssignmentResult struct { Update bool `json:"is_update,omitempty"` } -// Determine if this is an insufficient resources error type. -func isInsufficientResourcesErr(err *ApiError) bool { - return err != nil && IsNatsErr(err, JSInsufficientResourcesErr, JSMemoryResourcesExceededErr, JSStorageResourcesExceededErr) +// Determine if this is an insufficient resources' error type. +func isInsufficientResourcesErr(resp *JSApiStreamCreateResponse) bool { + return resp != nil && resp.Error != nil && IsNatsErr(resp.Error, JSInsufficientResourcesErr, JSMemoryResourcesExceededErr, JSStorageResourcesExceededErr) } // Process error results of stream and consumer assignments. @@ -3427,7 +3427,7 @@ func (js *jetStream) processStreamAssignmentResults(sub *subscription, c *client canDelete := !result.Update && time.Since(sa.Created) < 5*time.Second // See if we should retry in case this cluster is full but there are others. - if cfg, ci := sa.Config, sa.Client; cfg != nil && ci != nil && isInsufficientResourcesErr(result.Response.Error) && canDelete { + if cfg, ci := sa.Config, sa.Client; cfg != nil && ci != nil && isInsufficientResourcesErr(result.Response) && canDelete { // If cluster is defined we can not retry. if cfg.Placement == nil || cfg.Placement.Cluster == _EMPTY_ { // If we have additional clusters to try we can retry.