chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] [PATCH 1/2] tcp: disable interrupts


From: Jim Ursetto
Subject: Re: [Chicken-hackers] [PATCH 1/2] tcp: disable interrupts
Date: Sat, 16 Mar 2013 19:42:21 -0500

I'm positive the race conditions have to do with errno,
which is incompatible with SRFI-18 threads.  For example
in the connect loop, there are two possible context
switches in which errno can get overwritten:

1) On entrance to (fail), prior to ##sys#update-errno
2) Inside (fail), entering the continuation of
   (##sys#update-errno), just before the strerror

In 2)'s case the reported error message can be wrong.
In 1)'s case the error message and errno can be wrong.
In either case it's just the reported error that's wrong, not
the fact that an error occurred.

Florian, please try the attached patch.  It simply inlines
(fail), removing the context switch at 1), and also passes
the return value of ##sys#update-errno to strerror, eliminating 2).

Assuming this works, I can produce a patch to fix the rest
of the ##sys#update-errno + signal-hook clauses in the same way,
as this combination is unsafe with SRFI 18.

Note that once tcp-connect returns, all bets are off on
the validity of (errno) anyway.

Jim

Attachment: errno.diff.txt
Description: Text document


On Mar 16, 2013, at 4:37 PM, Felix wrote:

> From: Florian Zumbiehl <address@hidden>
> Subject: [Chicken-hackers] [PATCH 1/2] tcp: disable interrupts
> Date: Sat, 16 Mar 2013 17:56:41 +0100
> 
>> Add (declare (disable-interrupts)) to tcp so that errno doesn't get changed 
>> at
>> inappropriate points during execution.
>> ---
>> 
>> I don't really have a clue whether this is the correct way to do it, but
>> the code that was breaking before is not breaking anymore with this patch
>> applied ...
> 
> I'm not 100% sure about this. Send/receive of large amounts of data
> will not be interrupted by the scheduler with timer-interrupts
> disabled (the code will invoke the scheduler manually, but only if the
> read/write operations fail due to blocking or interrupted system
> calls). On the other hand adding the declarations will make the
> behaviour certainly more deterministic and might avoid hidden race
> conditions.
> 
> 
> cheers,
> felix
> 
> _______________________________________________
> Chicken-hackers mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-hackers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]