question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] StreamProvider.CreateStreamAsync garbage output due to memory cache

See original GitHub issue

I’m using MonoTorrent 2.0-rev0017 with StreamProvider and CreateStreamAsync. The stream doesn’t guarantee that bytes read from disk actually have been written.

https://github.com/alanmcgovern/monotorrent/blob/master/src/MonoTorrent/MonoTorrent.Streaming/LocalStream.cs#L113 This waits and switches on the availability bit (piece downloaded).

https://github.com/alanmcgovern/monotorrent/blob/master/src/MonoTorrent/MonoTorrent.Client.PieceWriters/DiskWriter.cs#L146 This buffers writes in-memory for performance. Therefore, no flush to disk until a threshold is passed.

This seems to result in the LocalStream reading while the DiskWriter hasn’t flushed (all) data yet. Therefore the stream is unreliable and produces garbage data, at times.

I can see two solutions right now:

Disable the cache Even then, there’s still an error window because read/write isn’t synchronized. If a read request request occurs during the window in which the writer is still writing, the reader will produce garbage, too. This makes me conclude that the same issue exists in older versions of monotorrent, except it’s less pronounced, because there’s less time that data isn’t available on-disk.

Synchronize reader to the writer This is the robust option. The local stream should be hooked into the writer, and only be able to read data that has been flushed to disk or is available in memory. This is also the most complex option.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Deathspikecommented, Dec 17, 2020

Seems to work just fine!

0reactions
alanmcgoverncommented, Dec 17, 2020

I’ve added tests covering the new cases and merged it all to master.

I’ll issue a new alpha release next week I’d say, so if you have time to test a master build in the meantime please do!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found