{"action":"created","issue":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4841","repository_url":"https://api.github.com/repos/RIOT-OS/RIOT","labels_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4841/labels{/name}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4841/comments","events_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4841/events","html_url":"https://github.com/RIOT-OS/RIOT/issues/4841","id":134389825,"number":4841,"title":"xtimer: timer already in the list","user":{"login":"immesys","id":4234131,"avatar_url":"https://avatars.githubusercontent.com/u/4234131?v=3","gravatar_id":"","url":"https://api.github.com/users/immesys","html_url":"https://github.com/immesys","followers_url":"https://api.github.com/users/immesys/followers","following_url":"https://api.github.com/users/immesys/following{/other_user}","gists_url":"https://api.github.com/users/immesys/gists{/gist_id}","starred_url":"https://api.github.com/users/immesys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/immesys/subscriptions","organizations_url":"https://api.github.com/users/immesys/orgs","repos_url":"https://api.github.com/users/immesys/repos","events_url":"https://api.github.com/users/immesys/events{/privacy}","received_events_url":"https://api.github.com/users/immesys/received_events","type":"User","site_admin":false},"labels":[{"id":23399098,"url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/bug","name":"bug","color":"fc2929","default":true},{"id":237926282,"url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/timer","name":"timer","color":"a00070","default":false},{"id":204289899,"url":"https://api.github.com/repos/RIOT-OS/RIOT/labels/TimerTaskForce","name":"TimerTaskForce","color":"f0c0ff","default":false}],"state":"open","locked":false,"assignee":{"login":"kaspar030","id":4679640,"avatar_url":"https://avatars.githubusercontent.com/u/4679640?v=3","gravatar_id":"","url":"https://api.github.com/users/kaspar030","html_url":"https://github.com/kaspar030","followers_url":"https://api.github.com/users/kaspar030/followers","following_url":"https://api.github.com/users/kaspar030/following{/other_user}","gists_url":"https://api.github.com/users/kaspar030/gists{/gist_id}","starred_url":"https://api.github.com/users/kaspar030/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaspar030/subscriptions","organizations_url":"https://api.github.com/users/kaspar030/orgs","repos_url":"https://api.github.com/users/kaspar030/repos","events_url":"https://api.github.com/users/kaspar030/events{/privacy}","received_events_url":"https://api.github.com/users/kaspar030/received_events","type":"User","site_admin":false},"assignees":[{"login":"kaspar030","id":4679640,"avatar_url":"https://avatars.githubusercontent.com/u/4679640?v=3","gravatar_id":"","url":"https://api.github.com/users/kaspar030","html_url":"https://github.com/kaspar030","followers_url":"https://api.github.com/users/kaspar030/followers","following_url":"https://api.github.com/users/kaspar030/following{/other_user}","gists_url":"https://api.github.com/users/kaspar030/gists{/gist_id}","starred_url":"https://api.github.com/users/kaspar030/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaspar030/subscriptions","organizations_url":"https://api.github.com/users/kaspar030/orgs","repos_url":"https://api.github.com/users/kaspar030/repos","events_url":"https://api.github.com/users/kaspar030/events{/privacy}","received_events_url":"https://api.github.com/users/kaspar030/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones/16","html_url":"https://github.com/RIOT-OS/RIOT/milestones/Release%202017.01","labels_url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones/16/labels","id":2079772,"number":16,"title":"Release 2017.01","description":"","creator":{"login":"miri64","id":675644,"avatar_url":"https://avatars.githubusercontent.com/u/675644?v=3","gravatar_id":"","url":"https://api.github.com/users/miri64","html_url":"https://github.com/miri64","followers_url":"https://api.github.com/users/miri64/followers","following_url":"https://api.github.com/users/miri64/following{/other_user}","gists_url":"https://api.github.com/users/miri64/gists{/gist_id}","starred_url":"https://api.github.com/users/miri64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miri64/subscriptions","organizations_url":"https://api.github.com/users/miri64/orgs","repos_url":"https://api.github.com/users/miri64/repos","events_url":"https://api.github.com/users/miri64/events{/privacy}","received_events_url":"https://api.github.com/users/miri64/received_events","type":"User","site_admin":false},"open_issues":252,"closed_issues":26,"state":"open","created_at":"2016-10-19T12:20:59Z","updated_at":"2016-11-22T17:30:49Z","due_on":"2017-01-31T00:00:00Z","closed_at":null},"comments":13,"created_at":"2016-02-17T20:22:53Z","updated_at":"2016-11-23T12:40:36Z","closed_at":null,"body":"I initially reported this on the mailing list, but I figured I should add an issue.\n\nI was getting strange lockups on my nodes, and managed to work out that a timer was being inserted into the list when it was already in the list, which would cause an infinite loop [here](https://github.com/RIOT-OS/RIOT/blob/master/sys/xtimer/xtimer_core.c#L209)\n\nI modified the function with this inside the while loop:\n\n``` C\nif (*list_head == timer || (*list_head)->next == timer){\n   disableIRQ();\n   while(1);\n}\n```\n\nAnd waited to see where the invocation was coming from. It triggered (on the second condition in the if statement), and this was the call chain:\n\n```\n#0  _add_timer_to_list (list_head=0x200021ac <sampling_stack+1755>, list_head@entry=0x20000630 <timer_list_head>, timer=timer@entry=0x2000148c <comms_stack+1832>) at //sys/xtimer/xtimer_core.c:226\n#1  0x00000d12 in _xtimer_set_absolute (timer=0x2000148c <comms_stack+1832>, target=1963159872) at //sys/xtimer/xtimer_core.c:197\n#2  0x00000dec in xtimer_set (timer=timer@entry=0x2000148c <comms_stack+1832>, offset=offset@entry=1000000) at //sys/xtimer/xtimer_core.c:133\n#3  0x00000a4e in xtimer_set_msg (target_pid=<optimized out>, msg=0x20001484 <comms_stack+1824>, offset=1000000, timer=0x2000148c <comms_stack+1832>) at //sys/xtimer/xtimer.c:124\n#4  xtimer_msg_receive_timeout (msg=msg@entry=0x200014bc <comms_stack+1880>, us=us@entry=1000000) at //sys/xtimer/xtimer.c:200\n#5  0x00001c94 in comms (arg=<optimized out>) at //Apps/accel/main.c:192\n#6  0x00000288 in sched_switch (other_prio=<optimized out>) at //core/sched.c:180\n#7  0x20001404 in comms_stack ()\n```\n\nThe comms thread looks basically like this (I am working on isolated reproducer):\n\n``` C\nmsg_t dns_msg; //type set to MSG_TYPE_DNS_TIMER once in main\nxtimer_t dns_timer; //nobody else uses this\nvoid *comms(void *arg)\n{\n  msg_t msg;\n  msg_init_queue(_comms_msg_queue, COMMS_QUEUE_SIZE);\n  gnrc_netreg_entry_t entry = { NULL, 4041, thread_getpid() };\n  gnrc_netreg_register(GNRC_NETTYPE_UDP, &entry))\n  while(1) {\n    if (xtimer_msg_receive_timeout(&msg, NETWORK_MAXRTT_US) < 0)\n      msg.type = MSG_TYPE_MUST_TX; //default to resending old packet\n    switch(msg.type) {\n      case GNRC_NETAPI_MSG_TYPE_RCV: {\n          /* snip */\n          gnrc_pktbuf_release((gnrc_pktsnip_t *) msg.content.ptr);\n          //Deliberately do not break\n      }\n      case MSG_TYPE_MUST_TX: { //Sent every ~100ms from sampling_thread\n          /* snip building packet 'ip' */\n          gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)\n          break;\n      }\n      case MSG_TYPE_DNS_TIMER: { //sent once by main, otherwise only to ourselves\n        update_dns_record(); //Sends a UDP packet, like above\n        xtimer_set_msg(&dns_timer, DNS_INTERVAL, &dns_msg, thread_getpid());\n        break;\n      }\n    } //end switch\n  } //end while\n} //endfun\n```\n\nSo essentially the `xtimer_msg_receive_timeout(&msg, NETWORK_MAXRTT_US)` is sometimes causing a stack-allocated timer to appear in the timer list twice. This is pretty interesting considering that [there is a call to remove the timer earlier in the call chain](https://github.com/RIOT-OS/RIOT/blob/master/sys/xtimer/xtimer_core.c#L122), although they are in different critical sections, so maybe something is happening between them.\n\nI will do my best to reproduce this with a small application that runs on the SAMR21-xpro.\n\nAlso, apologies if this is user error, I am still getting the hang of RIOT.\n"},"comment":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/comments/262502836","html_url":"https://github.com/RIOT-OS/RIOT/issues/4841#issuecomment-262502836","issue_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/4841","id":262502836,"user":{"login":"miri64","id":675644,"avatar_url":"https://avatars.githubusercontent.com/u/675644?v=3","gravatar_id":"","url":"https://api.github.com/users/miri64","html_url":"https://github.com/miri64","followers_url":"https://api.github.com/users/miri64/followers","following_url":"https://api.github.com/users/miri64/following{/other_user}","gists_url":"https://api.github.com/users/miri64/gists{/gist_id}","starred_url":"https://api.github.com/users/miri64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miri64/subscriptions","organizations_url":"https://api.github.com/users/miri64/orgs","repos_url":"https://api.github.com/users/miri64/repos","events_url":"https://api.github.com/users/miri64/events{/privacy}","received_events_url":"https://api.github.com/users/miri64/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T12:40:36Z","updated_at":"2016-11-23T12:40:36Z","body":"As https://github.com/RIOT-OS/RIOT/pull/6155#issuecomment-262395224 points out, that function is removed in that fix. But as far as I understood this there is also a bug in xtimer, not checking the identity of an added `xtimer_t` struct. This should be an easy fix to xtimer, doesn't it?"}}
{"actor":{"display_login":"miri64"}}