<p>Have you considered that by the time you call cancel, the timeout message may already be on its way to your process?<br>
One solution is to make your timeout messages versioned, and check the version at reception time.<br>
Another is to clear the inbox of pending timeout messages just after cancel returns.</p>
<div class="gmail_quote">Den 05/08/2012 06.33 skrev "Dmitry Kolesnikov" <<a href="mailto:dmkolesnikov@gmail.com">dmkolesnikov@gmail.com</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I am getting a wired eunit test failure. I am sorry,  the code is complicated and it cannot be share here. In nutshell, I do have a gen_server that uses timer:send_after(...) to send timeout message to itself, often it uses timeout equals to 0. If some other message arrives before timeout, then timer is cancelled by timer:cancel(...)<br>

<br>
Sometimes, with probability 1/5 - 1/6 timeout message is duplicated, see log below. However, if I switch to erlang:send_after and erlang:cancel_timer the issue disappears. Doe anyone seen a similar effect? Why timer duplicates message?<br>

<br>
<br>
07:21:51.683 [error] make timer: <0.183.0> T=0<br>
07:21:51.684 [error] timeout <0.183.0><br>
...<br>
07:21:51.693 [error] make timer: <0.183.0> T=0<br>
...<br>
07:21:51.695 [error] cancel timer: <0.183.0><br>
07:21:51.696 [error] make timer: <0.183.0> T = 0<br>
07:21:51.696 [error] timeout <0.183.0><br>
07:21:51.697 [error] make timer: <0.183.0> T = 0<br>
07:21:51.698 [error] cancel timer: <0.183.0><br>
07:21:51.699 [error] make timer: <0.183.0> T = 0<br>
07:21:51.699 [error] timeout <0.183.0><br>
07:21:51.700 [error] make timer: <0.183.0> T = 0<br>
07:21:51.701 [error] timeout <0.183.0><br>
07:21:51.701 [error] timeout <0.183.0><br>
<br>
Best Regards, Dmitry<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>