Skip to content

Commit

Permalink
Add DYING state, and use it instead of asking the core to delete the …
Browse files Browse the repository at this point in the history
…socket without SQUIT. Should fix the crash in bug #943

git-svn-id: http://svn.inspircd.org/repository/branches/1_2_stable@12316 e03df62e-2008-0410-955e-edbf42e46eb7
  • Loading branch information
danieldg committed Jan 23, 2010
1 parent 784f0cb commit 12711d0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/modules/m_spanningtree/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
{
TreeServer *s = i->second;

if (s->GetSocket() && s->GetSocket()->GetLinkState() == DYING)
s->GetSocket()->Squit(s, "split");

// Fix for bug #792, do not ping servers that are not connected yet!
// Remote servers have Socket == NULL and local connected servers have
// Socket->LinkState == CONNECTED
Expand Down
2 changes: 1 addition & 1 deletion src/modules/m_spanningtree/treesocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* CONNECTED: represents a fully authorized, fully
* connected server.
*/
enum ServerState { CONNECTING, WAIT_AUTH_1, WAIT_AUTH_2, CONNECTED };
enum ServerState { CONNECTING, WAIT_AUTH_1, WAIT_AUTH_2, CONNECTED, DYING };

/** Every SERVER connection inbound or outbound is represented by
* an object of type TreeSocket.
Expand Down
12 changes: 10 additions & 2 deletions src/modules/m_spanningtree/treesocket1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
*/
bool TreeSocket::OnDataReady()
{
if (LinkState == DYING)
return true;
const char* data = this->Read();
/* Check that the data read is a valid pointer and it has some content */
if (data && *data)
Expand All @@ -294,7 +296,11 @@ bool TreeSocket::OnDataReady()
*/
if (!this->ProcessLine(ret))
{
return false;
Utils->Creator->loopCall = false;
LinkState = DYING;
// returning false from this function is a bad
// idea, it causes deallocation too soon.
return true;
}
}
Utils->Creator->loopCall = false;
Expand All @@ -303,5 +309,7 @@ bool TreeSocket::OnDataReady()
/* EAGAIN returns an empty but non-NULL string, so this
* evaluates to TRUE for EAGAIN but to FALSE for EOF.
*/
return (data && !*data);
if (!data)
LinkState = DYING;
return true;
}
5 changes: 4 additions & 1 deletion src/modules/m_spanningtree/treesocket2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

void TreeSocket::WriteLine(std::string line)
{
if (LinkState == DYING)
return;
ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
line.append("\r\n");
this->Write(line);
Expand Down Expand Up @@ -96,6 +98,8 @@ bool TreeSocket::ProcessLine(std::string &line)
{
TreeServer* Node;

case DYING:
return false;
case WAIT_AUTH_1:
/*
* State WAIT_AUTH_1:
Expand Down Expand Up @@ -587,7 +591,6 @@ bool TreeSocket::ProcessLine(std::string &line)

}
return true;
break; // end of state CONNECTED (phew).
}
return true;
}
Expand Down

0 comments on commit 12711d0

Please sign in to comment.