Skip to content

Conversation

@chriso
Copy link
Contributor

@chriso chriso commented Oct 19, 2023

When serializing a durable coroutine, the serialized representation is probably only valid for the build that generated it.

There are no checks to ensure that the serialized representation of a coroutine is valid for a particular build. When the serialized representation is no longer valid, the program crashes with cryptic error messages.

This PR fixes the issue by prefixing the serialized representation with a build hash. If there's a hash mismatch, Unmarshal returns an ErrInvalidState error that the program can handle gracefully. For example, the program may choose to restart the coroutine.

Rather than hashing the binary (which might be large), we extract the Go Build ID and use it as the hash. The build ID changes when the source changes, but also when the compiler and any other dependencies change too (which both may affect the serialized representation of coroutines). I adapted the ELF and Mach-O parsers from https://github.com/golang/go/tree/3803c8588/src/cmd/internal/buildid, but kept it simple and only added a parser for binaries generated by the Go compiler (and not gccgo).

Copy link
Contributor

@achille-roussel achille-roussel left a comment

Choose a reason for hiding this comment

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

👏

@chriso chriso merged commit 26bd486 into main Oct 19, 2023
@chriso chriso deleted the buildid branch October 19, 2023 00:19
Copy link
Contributor

@pelletier pelletier left a comment

Choose a reason for hiding this comment

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

Nice!

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.

4 participants