gloebit / opensim-moneymodule-gloebit

OpenSim addon module integrating with the Gloebit digital currency service
GNU Lesser General Public License v3.0
8 stars 12 forks source link

Blocking calls in OnCompleteMovement can cause teleport failures #74

Closed mdickson closed 5 years ago

mdickson commented 5 years ago

On 0.9.1 -dev

The upcall to OnCompleteMovement is done directly from the UDP packet handler and before the ACK is sent. Because this can cause a balance inquiry to happen which is a potentionally long running call it can often cause teleport failures. The Ack to actually complete movement is never sent and the client just hangs and eventually times out.

I have a workaround for this in the Gloebits Module. I simply wrap the body of the OnCompleteMovement upcall function in a QueueUserWorkItem call and the call returns immediately. This lets the ACK be sent and the teleport actually completes. I'd argue this really could be better addressed by not sending events from a UDP packet handler but this fixes my problem for now.

colosi commented 5 years ago

Here is the actual code that @mdickson is referring to:

private void OnCompleteMovementToRegion(IClientAPI client, bool blah) 
{
    System.Threading.ThreadPool.QueueUserWorkItem(delegate 
    {
        // TODO: may now be albe to remove client from these funcs (since we moved this out of OnNewClient, but this still might be simpler.
        m_log.DebugFormat("[GLOEBITMONEYMODULE] OnCompleteMovementToRegion for {0} with bool {1}", client.AgentId, blah);
        m_log.DebugFormat("[GLOEBITMONEYMODULE] OnCompleteMovementToRegion SessionId:{0} SecureSessionId:{1}", client.SessionId, client.SecureSessionId);
        GloebitUser user = GloebitUser.Get(m_key, client.AgentId);
        // If authed, update balance immediately
        if (user.IsAuthed()) {
            // Don't send Buy Gloebits messaging so that we don't spam
            UpdateBalance(client.AgentId, client, 0);
        }
        if (user.IsNewSession(client.SessionId)) {
            // Send welcome messaging and buy gloebits messaging or auth messaging
            SendNewSessionMessaging(client, user);
        }
    }, null);
}

May need to determine if we need to do this or just make this asynchronous or do both.