Closed GoogleCodeExporter closed 9 years ago
Hmmm - an interesting v2 bug. Indeed, this should work. I'll investigate. As a
workaround, I'd be interested to know if calling the `PrepareSerializer<T>`
method (early on in the app) fixes this for now. (emph: workaround; I plan to
resolve this properly)
Original comment by marc.gravell
on 6 Sep 2010 at 6:19
Calling PrepareSerializer<T> for all involved T seems to fix the race.
BTW: My earlier comment about Serializer.Deserialize<> was wrong, it can happen
as part of deserialization as well.
Original comment by kasper.o...@gmail.com
on 6 Sep 2010 at 10:05
I can confirm the same problem.
I'm using nongeneric function and while deserializing using multiple threads i
get random exceptions.
I've fixed it using suggestion posted in comment 2;
after porting the PrepareSerializer function to NonGeneric.cs and using it to
inizialize all T the problem vanished.
Using protobuf-net rev. 359 under .Net 3.5
Original comment by tipolo...@gmail.com
on 9 Feb 2011 at 5:03
Any code I can use to repro would be appreciated...
Original comment by marc.gravell
on 9 Feb 2011 at 9:27
Here is a sample program that reproduces the problem.
On the first run it creates 16 files with some serialized data.
On the following run it read the files in memory stream (sequentially), then it
launch 16 threads that will deserialize the streams in parallel.
Please run it twice to reproduce the problem.
Let me know if you need the whole project, altough the code is very simple and
it only depends on protobuf-net.
Original comment by tipolo...@gmail.com
on 10 Feb 2011 at 10:41
Attachments:
Obviously the program i've posted reproduces the problem on the Deserialization
side, altough i think the problem described by the bug opener is the same as
mine.
P.S. Can you add PrepareSerializer in the NonGeneric.cs ?
I've added it as a quick fix for my project.
Original comment by tipolo...@gmail.com
on 10 Feb 2011 at 10:45
In v2, PrepareSerializer is actually synonymous with:
RuntimeTypeModel.Default[typeof(T)].CompileInPlace();
so you should find that:
RuntimeTypeModel.Default[someType].CompileInPlace();
does the job
Original comment by marc.gravell
on 10 Feb 2011 at 1:32
Yes, i've seen that; i've suggested the Prepareserializer implementation in
non-generic version just to be similar to the PrepareSerializer<T>
implementation present in generic version.
Obviously that's only a suggestion :)
Do you have tested my code? Let me know if you need something different..
Original comment by tipolo...@gmail.com
on 10 Feb 2011 at 1:39
I can add a PrepareSerializer in v2, sure. I'll get to the attachment when I
have a second; haven't had chance to try it yet. I'm sure it will be
illuminating.
Original comment by marc.gravell
on 11 Feb 2011 at 11:20
I've tracked down the problem to a race condition present in FindOrAddAuto, in
RuntimeTypeModel.cs
If two threads are trying to deserialize an object of some unprepared type,
both thread will try to prepare it, leading one of them throwing an exception
because the other has frozen the type.
I've applied a lock around all code inside FindOrAddAuto and the problem
vanished.
This imply that also the type find is interlocked, maybe losing a bit of
performance, but at least for me it solves the bug.
Hope to be helpful :)
Original comment by tipolo...@gmail.com
on 15 Feb 2011 at 2:58
Much obliged;
Original comment by marc.gravell
on 15 Feb 2011 at 3:39
any news on this?
Original comment by tipolo...@gmail.com
on 11 Apr 2011 at 9:45
all fixed
Original comment by marc.gravell
on 13 May 2011 at 8:07
Is this bug on the v2 branch and/or the v1 branch? We are currently using
version 1.0.0.282 on 12 core + hyperthreading servers.
Original comment by ray.rizzuto@gmail.com
on 30 Aug 2011 at 8:37
@ray.rizzuto neither, since it was fixed months ago. But it *used* to relate to
v2. The servers we use for stackexchange *also* have a great deal of
parallelism, and we have been using it there *extensively* for many months.
Original comment by marc.gravell
on 31 Aug 2011 at 5:25
Original issue reported on code.google.com by
kasper.o...@gmail.com
on 3 Sep 2010 at 12:57