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

Fix a rare crash in the garbage collector while restoring a workspace #5371

Merged
merged 3 commits into from
Feb 8, 2023

Conversation

ChrisJefferson
Copy link
Contributor

While we are loading a workspace, gasman is kept in a slightly-inconsistent state, with various pointers only set at the end. This means we mustn't call functions like NewBag, ResizeBag and (the problem we were hitting, subtly), CHANGED_BAG.

This stops objset/objmap from calling CHANGED_BAG, and adds asserts to make sure this doesn't happen again in future (and verifies nothing else is calling any of these methods).

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Great catch! Unfortunately it now has a conflict. I left a few suggestions.

src/gasman.c Outdated Show resolved Hide resolved
@@ -388,8 +388,14 @@ void CHANGED_BAG(Bag b);

extern Bag * YoungBags;
extern Bag ChangedBags;

#ifdef GAP_KERNEL_DEBUG
BOOL InWorkspaceRestore(void);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
BOOL InWorkspaceRestore(void);
BOOL InWorkspaceRestore(void);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The place where I've put it is where clang-format wants to put it (I guess to line us with the variables above?), so I'd prefer to leave it there, else it might just move in future if we ever clang-format everything.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. I thought it would be the other way around

src/objset.c Outdated Show resolved Hide resolved
@ChrisJefferson
Copy link
Contributor Author

Now (hopefully) all fixed up

src/objset.c Outdated
AddObjMapNew(new, obj,
READ_SLOT(map, i*2+1));
AddObjMapNew(new, obj, READ_SLOT(map, i * 2 + 1));
CHANGED_BAG(new);
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed as no GC can occur in this loop, and afterwards SwapMasterPointer ensures both bags are marked aa changed (so the two CHANGED_BAG calls after it could also go)

@fingolfin fingolfin enabled auto-merge (rebase) February 8, 2023 13:44
@fingolfin fingolfin added kind: bug Issues describing general bugs, and PRs fixing them kind: bug: crash Issues describing bugs that cause GAP to crash, and PRs fixing them (used for release notes) topic: kernel labels Feb 8, 2023
@fingolfin fingolfin merged commit 97a37e0 into gap-system:master Feb 8, 2023
@ChrisJefferson ChrisJefferson deleted the fix-objset branch December 18, 2023 07:10
@fingolfin fingolfin changed the title Stop calling CHANGED_BAG during workspace restore, as it can cause crashes Fix a rare crash in the garbage collector while restoring a workspace Jan 23, 2024
@fingolfin fingolfin added the release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes label Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug: crash Issues describing bugs that cause GAP to crash, and PRs fixing them (used for release notes) kind: bug Issues describing general bugs, and PRs fixing them release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants