Future.set_result is not safe to use with loop.call_soon() here is test for that issue: @mock.patch('asyncio.base_events.logger') ...
11 years, 2 months ago
(2014-03-03 22:03:25 UTC)
#1
Future.set_result is not safe to use with loop.call_soon()
here is test for that issue:
@mock.patch('asyncio.base_events.logger')
def test_ctor_with_cancelled_waiter(self,m_log):
fut = asyncio.Future(loop=self.loop)
@asyncio.coroutine
def foo():
_SelectorSocketTransport(
self.loop, self.sock, self.protocol, fut)
yield from fut
task = asyncio.async(foo(), loop=self.loop)
test_utils.run_once(self.loop)
task.cancel()
test_utils.run_briefly(self.loop)
self.assertTrue(fut.cancelled())
# exception should not be raised
self.assertFalse(m_log.error.called)
On 2014/03/03 22:03:25, Nikolay Kim wrote: > Future.set_result is not safe to use with loop.call_soon() ...
11 years, 2 months ago
(2014-03-03 22:04:52 UTC)
#2
On 2014/03/03 22:03:25, Nikolay Kim wrote:
> Future.set_result is not safe to use with loop.call_soon()
>
> here is test for that issue:
>
> @mock.patch('asyncio.base_events.logger')
> def test_ctor_with_cancelled_waiter(self,m_log):
> fut = asyncio.Future(loop=self.loop)
>
> @asyncio.coroutine
> def foo():
> _SelectorSocketTransport(
> self.loop, self.sock, self.protocol, fut)
> yield from fut
>
> task = asyncio.async(foo(), loop=self.loop)
> test_utils.run_once(self.loop)
> task.cancel()
> test_utils.run_briefly(self.loop)
> self.assertTrue(fut.cancelled())
>
> # exception should not be raised
> self.assertFalse(m_log.error.called)
i see this problem in production
Hmm... Are you just concerned about the log messages or is the logic of your ...
11 years, 2 months ago
(2014-03-03 22:33:01 UTC)
#3
Hmm... Are you just concerned about the log messages or is the logic of your app
compromised? Adding a new method to Future is a pretty drastic step (especially
since we are now past CPython 3.4 rc2).
I should add the behavior of set_result is intentional. Are you seeing these spurious log ...
11 years, 2 months ago
(2014-03-03 22:34:33 UTC)
#4
I should add the behavior of set_result is intentional. Are you seeing these
spurious log message for all the places that you are patching? Maybe we should
have a discussion on the tracker first, or on python-tulip?
On 2014/03/03 22:33:01, GvR wrote: > Hmm... Are you just concerned about the log messages ...
11 years, 2 months ago
(2014-03-03 22:46:21 UTC)
#5
On 2014/03/03 22:33:01, GvR wrote:
> Hmm... Are you just concerned about the log messages or is the logic of your
app
> compromised? Adding a new method to Future is a pretty drastic step
(especially
> since we are now past CPython 3.4 rc2).
it doesnt compromised app logic, just annoying. and problem with Cancelled
exception, it is very hard to understand where it is from.
i do not insists on immediate fix, but it should be fixed eventually.
Feb 28 00:28:03 ip-10-31-197-58 sqs-files ERROR [asyncio] Exception in callback
<bound method Future.set_result of Future<CANCELLED>>(None,)
handle: Handle(<bound method Future.set_result of Future<CANCELLED>>, (None,))
Traceback (most recent call last):
File
"/usr/local/lib/python3.3/dist-packages/asyncio-0.4.1_p1-py3.3.egg/asyncio/events.py",
line 39, in _run
self._callback(*self._args)
File
"/usr/local/lib/python3.3/dist-packages/asyncio-0.4.1_p1-py3.3.egg/asyncio/futures.py",
line 298, in set_result
raise InvalidStateError('{}: {!r}'.format(self._state, self))
asyncio.futures.InvalidStateError: CANCELLED: Future<CANCELLED>
On 2014/03/03 22:34:33, GvR wrote: > I should add the behavior of set_result is intentional. ...
11 years, 2 months ago
(2014-03-03 22:49:48 UTC)
#6
On 2014/03/03 22:34:33, GvR wrote:
> I should add the behavior of set_result is intentional. Are you seeing these
> spurious log message for all the places that you are patching? Maybe we should
> have a discussion on the tracker first, or on python-tulip?
sure, let's discuss on python-tulip
On 2014/03/03 22:49:48, Nikolay Kim wrote: > On 2014/03/03 22:34:33, GvR wrote: > > I ...
11 years, 2 months ago
(2014-03-04 17:40:26 UTC)
#7
On 2014/03/03 22:49:48, Nikolay Kim wrote:
> On 2014/03/03 22:34:33, GvR wrote:
> > I should add the behavior of set_result is intentional. Are you seeing these
> > spurious log message for all the places that you are patching? Maybe we
should
> > have a discussion on the tracker first, or on python-tulip?
>
> sure, let's discuss on python-tulip
this patch uses helper function
https://codereview.appspot.com/69870048/diff/20001/asyncio/events.py File asyncio/events.py (right): https://codereview.appspot.com/69870048/diff/20001/asyncio/events.py#newcode20 asyncio/events.py:20: pass Instead of catching InvalidStateError, I would prefer to ...
10 years, 10 months ago
(2014-06-30 14:15:34 UTC)
#10
Issue 69870048: Future.set_result is not safe
Created 11 years, 2 months ago by Nikolay Kim
Modified 10 years, 10 months ago
Reviewers: GvR, haypo_gmail
Base URL:
Comments: 5