Skip to content

Commit

Permalink
Remove existing thread state for clone children
Browse files Browse the repository at this point in the history
When parsing clone exit events, specifically for the child half of a
clone and when in a container, always remove any existing thread state
that may be attached to the event and remove that state from the thread
manager.

This matches the logic on the parent side, which is to let the child
create the thread.

This ensures that if there does happen to be an existing thread state
from an old thread that happened to share the same thread id, that it
will be removed.

This fixes #664.
  • Loading branch information
mstemm committed Oct 22, 2016
1 parent 437b6ce commit 833f790
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,22 @@ void sinsp_parser::parse_clone_exit(sinsp_evt *evt)
{
//
// clone() returns 0 in the child.
//

//
// If the threadinfo in the event exists, and we're in
// a container, the threadinfo in the event must be
// stale (e.g. from a prior process with the same
// tid), because only the child side of a clone
// creates the threadinfo for the child. Clear and
// remove the old threadinfo.
//
if(evt->m_tinfo && in_container)
{
m_inspector->remove_thread(tid, true);
evt->m_tinfo = NULL;
}

// Validate that the child thread info has actually been created.
//
if(!evt->m_tinfo)
Expand Down Expand Up @@ -998,17 +1014,8 @@ void sinsp_parser::parse_clone_exit(sinsp_evt *evt)
else
{
//
// We are in the child's clone. If we are in a container, make
// sure the vtid/vpid are reflected because the father was maybe
// running outside the container so created the child thread without
// knowing the internal vtid/vpid
// Let the parent create the threadinfo for the child
//
if(in_container)
{
evt->m_tinfo->m_vtid = vtid;
evt->m_tinfo->m_vpid = vpid;
}

return;
}
}
Expand Down

0 comments on commit 833f790

Please sign in to comment.