Serveral times a day i get this
TCP receive failed
read: socket: WSAECONNRESET
error in my unity console than my connection to perforce dies as well as the unity p4 integration.
Has anyone been able to figure out why this problem is happening?
I am 90% it is not a problem with my p4 server since my p4v and p4vs clients seem to stay connected when this error happens.
Also getting this. Unity hangs for 10-30 seconds and then gives me this error. Getting frustrating. Did you ever find a solution @cmcpasserby ?
It’s happening because of some artificial timeout in the Perforce plugin. It only seeks to keep the connection open when the browser is active. I have a solution, but first I have to tell you what doesn’t work.
I tried to keep the Editor “fresh” by writing a C# application that sends virtual keyboard inputs to the Unity process without having to pull focus at all. While it does actually input in Unity, it wasn’t enough of an interaction with the editor to cause the connection to stay alive.
So what does work?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class P4WSACONNRESET_Workaround : MonoBehaviour
{
private static double lastRefresh = 0;
private static double refreshInterval = 120000;
[UnityEditor.Callbacks.DidReloadScripts]
public static void DoWSAConnReset_Workaround()
{
EditorApplication.delayCall -= StartAssetDatabaseRefreshInterval;
if (EditorApplication.isCompiling || EditorApplication.isUpdating)
{
EditorApplication.delayCall += StartAssetDatabaseRefreshInterval;
return;
}
EditorApplication.delayCall += StartAssetDatabaseRefreshInterval;
}
public static void StartAssetDatabaseRefreshInterval()
{
EditorApplication.update -= HandleEditorApplicationUpdate;
EditorApplication.update += HandleEditorApplicationUpdate;
}
public static void HandleEditorApplicationUpdate()
{
if (EditorApplication.timeSinceStartup - lastRefresh > refreshInterval)
{
AssetDatabase.Refresh();
lastRefresh = EditorApplication.timeSinceStartup;
string dateTime = DateTime.Now.ToString("F");
Debug.LogFormat("Poke AssetDatabase {0}", dateTime);
}
}
}
Thanks to SisusCo’s post here, I found a way to invoke a script to execute automatically without any sort of manual “pump”. It even works when you open the editor. Currently it’s set for a 2 minute interval, but you can change it. I am posting this as soon as I got it going and confirmed it worked between editor starts so I haven’t had time to understand what the exact time is that the Perforce plugin has before it loses connection. Would be ideal to set the interval to just below that. The AssetDatabase.Refresh call doesn’t seem to cause any hit that I could notice because nothing is changing when you’re out of the editor that it isn’t already aware of.