From deadbc57d9c4fe10112cc91d5813e8acd4196abf Mon Sep 17 00:00:00 2001 From: Yorhel Date: Wed, 4 Nov 2009 15:03:37 +0100 Subject: Fixed infinite loop bug on SQL error in the canwrite event This is actually caused by two bugs: - The query that caused the error is not removed from the queue, so it will be executed again. (triggering another error) - The select_write() is still active on the socket, even when we don't have anything to write. I've been aware of this bug for quite a while, but could never track it down. Now I finally know what really happened when my applications got in an infinite loop. --- lib/POE/Component/Pg.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/POE/Component/Pg.pm b/lib/POE/Component/Pg.pm index a68966b..a31b6b5 100644 --- a/lib/POE/Component/Pg.pm +++ b/lib/POE/Component/Pg.pm @@ -296,13 +296,16 @@ sub dbi_canwrite { $_[HEAP]{q}->execute($item->[QPARAM] && ref($item->[QPARAM]) eq 'ARRAY' ? @{$item->[QPARAM]} : ()); }; + # no need to write anymore + $_[KERNEL]->select_pause_write($_[HEAP]{fh}); + # send error or enter read state if($@) { sendevent \@_, 'error', $item->[QACT], $@, $item->[QQUERY], $item->[QPARAM], $item->[QSESID], $item->[QARG]; + shift @{$_[HEAP]{queue}}; $_[KERNEL]->call($_[SESSION], 'process_queue'); } else { $_[HEAP]{state} = 2; - $_[KERNEL]->select_pause_write($_[HEAP]{fh}); } } -- cgit v1.2.3