ctstone / csredis

.NET client for Redis and Redis Sentinel (2.8). Includes both synchronous and asynchronous clients.
Other
292 stars 111 forks source link

WriteAsync notsupported exception #17

Closed bonesoul closed 10 years ago

bonesoul commented 10 years ago

Frequently happens within async methods;

RedisWriter.cs
        Task WriteAsync(byte[] data)
        {
            var tcs = new TaskCompletionSource<bool>();
            _streamBuffer.BeginWrite(data, 0, data.Length, ar =>
            {
                _streamBuffer.EndWrite(ar);
                tcs.SetResult(true);
            }, null);
            return tcs.Task;
        }
System.NotSupportedException was unhandled by user code
  HResult=-2146233067
  Message=Cannot write to a BufferedStream while the read buffer is not empty if the underlying stream is not seekable. Ensure that the stream underlying this BufferedStream can seek or avoid interleaving read and write operations on this BufferedStream.
  Source=mscorlib
  StackTrace:
       at System.IO.BufferedStream.ClearReadBufferBeforeWrite()
       at System.IO.BufferedStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
       at CSRedis.Internal.IO.RedisWriter.WriteAsync(Byte[] data) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\IO\RedisWriter.cs:line 166
       at CSRedis.Internal.IO.RedisWriter.WriteMultiBulkAsync(Int32 size) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\IO\RedisWriter.cs:line 86
       at CSRedis.Internal.IO.RedisWriter.WriteAsync(String command, Object[] args) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\IO\RedisWriter.cs:line 47
       at CSRedis.Internal.RedisConnection.<>c__DisplayClass6`1.<CallAsync>b__2() in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\RedisConnection.cs:line 105
       at CSRedis.Internal.RedisConnection.WriteNext() in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\RedisConnection.cs:line 198
       at CSRedis.Internal.RedisConnection.<CallAsync>b__5[T](Task`1 x) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\RedisConnection.cs:line 109
       at System.Threading.Tasks.Task.Execute()
  InnerException: 
ctstone commented 10 years ago

Thanks for this. Looks like there is a concurrency bug here.

On Tue, Aug 5, 2014 at 10:32 AM, Hüseyin Uslu notifications@github.com wrote:

Frequently happens within async methods;

RedisWriter.cs Task WriteAsync(byte[] data) { var tcs = new TaskCompletionSource(); _streamBuffer.BeginWrite(data, 0, data.Length, ar => { _streamBuffer.EndWrite(ar); tcs.SetResult(true); }, null); return tcs.Task; }

System.NotSupportedException was unhandled by user code HResult=-2146233067 Message=Cannot write to a BufferedStream while the read buffer is not empty if the underlying stream is not seekable. Ensure that the stream underlying this BufferedStream can seek or avoid interleaving read and write operations on this BufferedStream. Source=mscorlib StackTrace: at System.IO.BufferedStream.ClearReadBufferBeforeWrite() at System.IO.BufferedStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state) at CSRedis.Internal.IO.RedisWriter.WriteAsync(Byte[] data) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\IO\RedisWriter.cs:line 166 at CSRedis.Internal.IO.RedisWriter.WriteMultiBulkAsync(Int32 size) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\IO\RedisWriter.cs:line 86 at CSRedis.Internal.IO.RedisWriter.WriteAsync(String command, Object[] args) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\IO\RedisWriter.cs:line 47 at CSRedis.Internal.RedisConnection.<>cDisplayClass6`1.b2() in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\RedisConnection.cs:line 105 at CSRedis.Internal.RedisConnection.WriteNext() in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\RedisConnection.cs:line 198 at CSRedis.Internal.RedisConnection.b__5[T](Task`1 x) in e:\Coding\CoiniumServ\deps\csredis\CSRedis\Internal\RedisConnection.cs:line 109 at System.Threading.Tasks.Task.Execute() InnerException:

— Reply to this email directly or view it on GitHub https://github.com/ctstone/csredis/issues/17.

ctstone commented 10 years ago

Async performance should be back to normal on the master branch. 65a7afd723660b263dca0adc31569e7b26ce5720

Nuget update coming soon

bonesoul commented 10 years ago

Is it a performance-wise update or it also fixes the above exception?

ctstone commented 10 years ago

Exception is fixed now