Skip to content

Check for nullptr when locking#5857

Merged
duke8253 merged 1 commit intoapache:masterfrom
duke8253:master-check_null
Aug 21, 2019
Merged

Check for nullptr when locking#5857
duke8253 merged 1 commit intoapache:masterfrom
duke8253:master-check_null

Conversation

@duke8253
Copy link
Copy Markdown
Contributor

@duke8253 duke8253 commented Aug 21, 2019

We need to check if the mutex pointer is actually pointing to something before using it, such that calling SCOPED_MUTEX_LOCK doesn't crash.

@duke8253 duke8253 added the Core label Aug 21, 2019
@duke8253 duke8253 added this to the 9.1.0 milestone Aug 21, 2019
@duke8253 duke8253 self-assigned this Aug 21, 2019
@duke8253 duke8253 merged commit d75af6f into apache:master Aug 21, 2019
@masaori335
Copy link
Copy Markdown
Contributor

I understand this change save the crash, but I'm not sure this is what we should do. Because this change allows us to write something like below.

Ptr<ProxyMutex> mutex = nullptr;
// long long line...
SCOPED_MUTEX_LOCK(lock, mutex, this_ethread());

If I look at the SCOPED_MUTEX_LOCK, I assume the mutex is acquired in this scope, but actually, it's not.

IMO, I think we should make sure nullptr is not given by release assert instead of nullptr check.

@SolidWallOfCode
Copy link
Copy Markdown
Member

In that case, there are no unlocked mutexes when the continuation is called. There are cases where having no mutex is desirable, for instance all of the data is static and locking is only overhead. How should that be done?

@maskit
Copy link
Copy Markdown
Member

maskit commented Aug 22, 2019

There are cases where having no mutex is desirable

I think we should have another macro for the use cases. This is scoped mutex lock.

@duke8253 duke8253 deleted the master-check_null branch August 26, 2019 19:29
@zwoop
Copy link
Copy Markdown
Contributor

zwoop commented Aug 27, 2019

What's particularly bothersome here is that the entire contract on how we use mutexes has changed now. I'm definitely not sure this is the right thing to do. And, this patch doesn't change any existing usage, so I imagine there are cases now where we double check the mutex variable. And, in a majority (almost always?) of the time, mutexes are not not nullptr, so we're doing this additional check for nothing.

@zwoop zwoop modified the milestones: 9.1.0, 10.0.0 Aug 27, 2019
@zwoop
Copy link
Copy Markdown
Contributor

zwoop commented Aug 27, 2019

This feels like 1) It hides real issues 2) Confuses an existing, well known API, 3) Doesn't follow a contract the way it looks / was designed. I think we should revert this, and places where a mutex can be nullptr, it's definitely preferable to be explicit, e.g. I find this more obvious:

if (m) {
    SCOPED_MUTEX_LOCK(l, m);
}

whereas after this patch, SCOPED_MUTEX_LOCK can silently become a no-op, just as @masaori335 points out.

@SolidWallOfCode
Copy link
Copy Markdown
Member

Yes, we're addressing all of that over on #5879. Our problem is, absent a change like this, we get assert crashes in high concurrency TLS operations.

@bryancall
Copy link
Copy Markdown
Contributor

Cherry picked to the 9.0.x branch.

@bryancall bryancall modified the milestones: 10.0.0, 9.0.0 Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants