Repository: minio/minio (language: go)

Issue:
cache version deprecated (will autoupdate) then panic: runtime error: invalid memory address or nil pointer dereference
Hello,

We do have a strange issue after updating from 2020-04-23T00-58-49Z to 2022-07-30T05-21-40Z.

After a while, minio crash with the following error:

> Aug 02 21:33:26 minio05 minio[34426]: API: SYSTEM()
> Aug 02 21:33:26 minio05 minio[34426]: Time: 19:33:26 UTC 08/02/2022
> Aug 02 21:33:26 minio05 minio[34426]: DeploymentID: 1070340e-9e48-4f38-83e4-1434b428e7da
> Aug 02 21:33:26 minio05 minio[34426]: Error: cache version deprecated (will autoupdate) (*errors.errorString)
> Aug 02 21:33:26 minio05 minio[34426]:        5: internal/logger/logger.go:259:logger.LogIf()
> Aug 02 21:33:26 minio05 minio[34426]:        4: internal/logger/logonce.go:101:logger.(*logOnceType).logOnceIf()
> Aug 02 21:33:26 minio05 minio[34426]:        3: internal/logger/logonce.go:132:logger.LogOnceIf()
> Aug 02 21:33:26 minio05 minio[34426]:        2: cmd/data-usage-cache.go:919:cmd.(*dataUsageCache).load()
> Aug 02 21:33:26 minio05 minio[34426]:        1: cmd/erasure.go:460:cmd.erasureObjects.nsScanner.func3()
> Aug 02 21:33:26 minio05 minio[34426]: panic: runtime error: invalid memory address or nil pointer dereference
> Aug 02 21:33:26 minio05 minio[34426]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc0c597]
> Aug 02 21:33:26 minio05 minio[34426]: goroutine 209318 [running]:
> Aug 02 21:33:26 minio05 minio[34426]: github.com/minio/minio/internal/logger.(*logOnceType).logOnceIf(0xc00028a340, {0x4d414d8, 0xc0191e98c0}, {0x4d28600, 0xc01b3e2c40}, {0x27e355a, 0x2a}, {0x0, 0x0, 0x0})
> Aug 02 21:33:26 minio05 minio[34426]:         github.com/minio/minio/internal/logger/logonce.go:96 +0xf7
> Aug 02 21:33:26 minio05 minio[34426]: github.com/minio/minio/internal/logger.LogOnceIf({0x4d414d8, 0xc0191e98c0}, {0x4d28600, 0xc01b3e2c40}, {0x27e355a, 0x2a}, {0x0, 0x0, 0x0})
> Aug 02 21:33:26 minio05 minio[34426]:         github.com/minio/minio/internal/logger/logonce.go:132 +0xc5
> Aug 02 21:33:26 minio05 minio[34426]: github.com/minio/minio/cmd.(*dataUsageCache).load(0xc0151f1400, {0x4d41468?, 0xc01646c400?}, {0x4d3b058, 0xc0191e9860}, {0xc015a1bf50, 0x25})
> Aug 02 21:33:26 minio05 minio[34426]:         github.com/minio/minio/cmd/data-usage-cache.go:919 +0x3f2
> Aug 02 21:33:26 minio05 minio[34426]: github.com/minio/minio/cmd.erasureObjects.nsScanner.func3(0x2?)
> Aug 02 21:33:26 minio05 minio[34426]:         github.com/minio/minio/cmd/erasure.go:460 +0x33e
> Aug 02 21:33:26 minio05 minio[34426]: created by github.com/minio/minio/cmd.erasureObjects.nsScanner
> Aug 02 21:33:26 minio05 minio[34426]:         github.com/minio/minio/cmd/erasure.go:446 +0x8f3
> Aug 02 21:33:26 minio05 systemd[1]: minio.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

A few remark:

* There was an error dues to `xxx is part of root disk, will not be used`, but we fixed it. However, the cluster ran for 15-30m in that state.
* Crash is random, but probably dues to random crawling ? All nodes crash after a while
* Healing only return green objects
* The error was also present before we moved data to a non-root disk


## Your Environment

* Version used (`minio --version`): 2022-07-30T05-21-40Z
* Server setup and configuration: Debian, LXC containers
* Operating System and version (`uname -a`): Linux minio05 5.15.39-1-pve #1 SMP PVE 5.15.39-1 (Wed, 22 Jun 2022 17:22:00 +0200) x86_64 GNU/Linux

Thanks for your help


Discussion / hints:
are you using gateway? @the-glu 
> We do have a strange issue after updating from 2020-04-23T00-58-49Z to 2022-07-30T05-21-40Z.

This too old looks like you messed up your setup. 
No gateway and yes, it's a testing setup ^^'

I just checked the code and it look like the line  github.com/minio/minio/internal/logger/logonce.go:96 was recently introduced - if I understand correctly it crash there, is it possible there is an issue in the logging function ?
Yes this is a specific problem @the-glu in this case - fixing. 

Fix patch:
diff --git a/internal/logger/logonce.go b/internal/logger/logonce.go
index 26e7b9fed6515..63a3ec7c84b1b 100644
--- a/internal/logger/logonce.go
+++ b/internal/logger/logonce.go
@@ -75,6 +75,9 @@ func unwrapErrs(err error) (leafErr error) {
 			break
 		}
 	}
+	if uerr == nil {
+		leafErr = err
+	}
 	return leafErr
 }
 


Test patch: