Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: nil dereference in FileApiLite::GetEpoch #408

Merged
merged 1 commit into from
May 9, 2023
Merged

Conversation

mitjat
Copy link
Contributor

@mitjat mitjat commented May 5, 2023

No description provided.

@mitjat mitjat requested review from aefhm, Andrew7234 and pro-wh as code owners May 5, 2023 06:46
@mitjat mitjat enabled auto-merge May 5, 2023 06:46
Copy link
Collaborator

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what causes this? doesn't it make a real time variable inside and & it? how does it become nil

@mitjat
Copy link
Contributor Author

mitjat commented May 8, 2023

how does it become nil

The caching layer can return a nil in some cases. I think #409 might get rid of all those cases, but still, best not to assume too much here.

I wish I had kept better notes, I only remember for sure that I encountered a nil dereference error here in the wild.

@mitjat mitjat requested a review from pro-wh May 8, 2023 20:44
@mitjat
Copy link
Contributor Author

mitjat commented May 8, 2023

Ah, I've just had it happen again :)

Whenever the internal RPC-calling func returns an error, the KVStore helper replaces the value with nil: https://github.com/oasisprotocol/oasis-indexer/blob/614a82493e881fc2e0584ec969657b64f02e67a0/storage/oasis/nodeapi/file/common.go#L94

Where I encountered it was during shutdown (ctrl+C or k8s SIGTERM), because the RPC-based ConsensusApiLite gets closed mid-request. It should also happen in case of intermittent IO problems etc.

@pro-wh
Copy link
Collaborator

pro-wh commented May 8, 2023

KVStore helper replaces the value with nil

but then err != nil and we'd bail before trying to dereference

@pro-wh
Copy link
Collaborator

pro-wh commented May 8, 2023

oh wait that link goes to a different function yeah

Copy link
Collaborator

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I never really looked into why GetFromCacheOrCall required it to be a pointer

@mitjat mitjat force-pushed the mitjat/getepoch-nil branch from 62832f0 to caf6b53 Compare May 9, 2023 19:54
@mitjat mitjat force-pushed the mitjat/getepoch-nil branch from caf6b53 to 05d85fd Compare May 9, 2023 19:57
@mitjat mitjat merged commit ae2b9d4 into main May 9, 2023
@mitjat mitjat deleted the mitjat/getepoch-nil branch May 9, 2023 20:04
@mitjat
Copy link
Contributor Author

mitjat commented May 9, 2023

ok I never really looked into why GetFromCacheOrCall required it to be a pointer

It probably technically doesn't, and we could return the default value instead. I used the pointer because functions in Go that return (ValueType, error) seem to prefer ValueType to be a pointer, and a nil signifies to me the optionality of a response a little more clearly. I might well be unknowingly going against a GoLang pointer use convention though :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants