Skip to content

add LOCK() for proxy related data-structures - #1859

Merged
sipa merged 1 commit into
bitcoin:masterfrom
Diapolo:proxy_locks
Oct 7, 2012
Merged

sipa merged 1 commit into
bitcoin:masterfrom
Diapolo:proxy_locks

Conversation

@Diapolo

@Diapolo Diapolo commented Sep 23, 2012

Copy link
Copy Markdown
  • fix proxyInfo isnt locked #1560 by properly locking proxy related data-structures
  • introduce GetProxyPair() and GetNameProxyPair() to be able to use a
    thread-safe local copy from proxyInfo and nameproxyInfo
  • rename GetNameProxy() into HaveNameProxy() to be more clear

Comment thread src/netbase.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using one "proxy info" lock would be enough, no need for a separate one for the nameproxy.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Indeed, fixed!

@BitcoinPullTester

Copy link
Copy Markdown

@laanwj

laanwj commented Sep 24, 2012

Copy link
Copy Markdown
Member

ACK

Comment thread src/netbase.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holding the cs_proxyInfos lock all through ConnectSocket and it's subroutines is bad practice.

How about something like:
proxyType proxy; { LOCK(cs_proxyInfos); proxy = proxyInfo[addrDest.GetNetwork()]; }
... proceed, with local copy of proxy...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or... We already have a GetProxy function to encapsulate getting values from proxyInfo, why not use it here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Just to understand, a lock is persistent in a function scope, right? So when I have a lock in a sub-function used in ConnectSocket it is released, when returning back to ConnectSocket.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A scoped lock is acquired where you define it with LOCK(), and it is released immediately at the end of the block (}) in which you define it. So, yes.

@Diapolo

Diapolo commented Sep 28, 2012

Copy link
Copy Markdown
Author

I'm going to update this until early next week :).

@Diapolo

Diapolo commented Sep 28, 2012

Copy link
Copy Markdown
Author

Updated to include 2 new functions to use local copies of the proxyInfo and nameproxyInfo objects in the time-critical functions, which removes the bad practise of holding the lock all through ConnectSocket and it's subroutines, as Gavin suggested.

I chose to add these 2 function (currently not exposed to netbase.h), because I think I need those when updating the GUI with extended proxy settings.

Comment thread src/netbase.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What "is" a name proxy? I agree GetNameProxy() currently doesn't make sense either, but I'd go for HaveNameProxy().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Seems better suited, yes.

@Diapolo

Diapolo commented Sep 29, 2012

Copy link
Copy Markdown
Author

@sipa I updated GetProxy() to fill a proxyType object and make that usable outsite of netbase.cpp (moved the typedef to netbase.h).
@laanwj Can you have a in depth look at the changes to optionsmodel.cpp, I included the use of GetProxy() for the SOCKS version, too, which was not in before (was read from the settings only).

Comment thread src/qt/optionsmodel.cpp

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@laanwj I was asking myself, if this should be changed into, as data() returns active state for IP, port and SOCKS version, too.

        case ProxyUse: {
            proxyType proxy;
            return QVariant(GetProxy(NET_IPV4, proxy));
        }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could be better because that better represents the current configuration, but leave that for a later pull. Aim to keep functionality precisely the same in these commits.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Understood :), thanks for your valuable input master!

@sipa

sipa commented Sep 30, 2012

Copy link
Copy Markdown
Member

ACK on changes to core.

@BitcoinPullTester

Copy link
Copy Markdown

@Diapolo

Diapolo commented Sep 30, 2012

Copy link
Copy Markdown
Author

@laanwj Anything left for the Qt changes? I trie to not include feature-changes and will do that after this got merged.

@laanwj

laanwj commented Oct 2, 2012

Copy link
Copy Markdown
Member

ACK

@Diapolo

Diapolo commented Oct 2, 2012

Copy link
Copy Markdown
Author

No code changes, only updated some code-layout in optionsmodel.cpp.

Comment thread src/netbase.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd suggest using the return value of GetProxy here, instead of querying proxy.second later on. It's a little bit more readable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, good idea ... and updated :).

- fix #1560 by properly locking proxy related data-structures
- update GetProxy() and introduce GetNameProxy() to be able to use a
  thread-safe local copy from proxyInfo and nameproxyInfo
- update usage of GetProxy() all over the source to match the new
  behaviour, as it now fills a full proxyType object
- rename GetNameProxy() into HaveNameProxy() to be more clear
@Diapolo

Diapolo commented Oct 5, 2012

Copy link
Copy Markdown
Author

Can we get this fix into 0.7.1?

@laanwj

laanwj commented Oct 5, 2012

Copy link
Copy Markdown
Member

Yes as I said on the mailing list, that's the goal.

Avoiding corner-case random crashes is always good.

sipa added a commit that referenced this pull request Oct 7, 2012
add LOCK() for proxy related data-structures
@sipa
sipa merged commit 43de649 into bitcoin:master Oct 7, 2012
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proxyInfo isnt locked

5 participants