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

ArgumentOutOfRangeException when accessing ConnectionMultiplexer log #1108

Closed
paveliak opened this issue Apr 3, 2019 · 6 comments
Closed

Comments

@paveliak
Copy link
Contributor

paveliak commented Apr 3, 2019

Hi

I got an ArgumentOutOfRangeException exception when calling ToString() for the ConnectionMultiplexer log. From the code it looks like all writes to the TextWriter object are synchronized inside the StackExchange.Redis code so the only thing that comes into my mind is that writes might continue after Connect() method returns and then ToString() method collides with those writes. Does it sound plausible?

FWIW we are using v1.2.6.

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: chunkLength

at System.Text.StringBuilder.ToString()
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
...

Here is our code:

var log = new StringWriter();
ConnectionMultiplexer mux = ConnectionMultiplexer.Connect(configurationOptions, log);
Trace($"ConnectionMultiplexerCreated: id={m_id}, log={log}");

Thanks,
Pavel

@mgravell
Copy link
Collaborator

mgravell commented Apr 4, 2019

My guess here is that there was a delayed operation in a race condition; suggested workaround:

var log = new StringWriter();
ConnectionMultiplexer mux = ConnectionMultiplexer.Connect(configurationOptions, log);
string logText;
lock (log) { logText = log.ToString(); }
Trace($"ConnectionMultiplexerCreated: id={m_id}, log={logText}");

@mgravell mgravell closed this as completed Apr 4, 2019
@paveliak
Copy link
Contributor Author

paveliak commented Apr 5, 2019

Thanks @mgravell although I am puzzled how locking on StringWriter object would help here because ConnectionMultiplexer locks on LogSyncLock (different) object when writing into "log".

@mgravell
Copy link
Collaborator

mgravell commented Apr 5, 2019

Oh, you're right - my bad; I incorrectly remembered what it locked on - I thought it locked on the log. So, er... yeah, that's a fun problem. Let me think on that.

@mgravell
Copy link
Collaborator

mgravell commented Apr 5, 2019

(for context: from distant memory, I suspect that at one point it did lock on the log instance, and then we hit a problem where someone else was also locking on the log instance, and ... well, bad things)

@mgravell
Copy link
Collaborator

mgravell commented Apr 5, 2019

I think what I'm going to have to do here is create a proxy to the log object, so that I can wipe it once (inside the lock etc) before leaving Connect/ConnectAsync, and then immediately: any future attempts to write to the log will fail. That's my plan, anyways!

@paveliak
Copy link
Contributor Author

paveliak commented Apr 5, 2019

Sounds good. Meanwhile I will wrap ToString() with try/catch.

@mgravell mgravell reopened this Apr 8, 2019
mgravell added a commit that referenced this issue Apr 8, 2019
…ter; move the sync to there - allows safe detach from the logging
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

No branches or pull requests

2 participants