Skip to content

Commit 01bfd73

Browse files
committed
Make timeout longer
Server wait timeout: 1minutes -> 2minutes Client connection timeout: 1 sec -> 15 sec
1 parent f4c2a2d commit 01bfd73

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

RepostConfirmationCanceler/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void LogImpl(Exception e)
8080

8181
private string GetTimestamp()
8282
{
83-
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
83+
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
8484
}
8585

8686
private void RotateIfNeed()

RepostConfirmationCanceler/ProcessCommunicator.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,34 @@ private static string GeneratePipeName()
2727
return $"{NAMED_PIPE_NAME_BASE}_{sid}";
2828
}
2929

30+
internal static void LogThreadStatus(RuntimeContext context)
31+
{
32+
try
33+
{
34+
ThreadPool.GetAvailableThreads(out int workerThreads, out int completionPortThreads);
35+
ThreadPool.GetMaxThreads(out int maxWorkerThreads, out int maxCompletionPortThreads);
36+
37+
int usedWorkerThreads = maxWorkerThreads - workerThreads;
38+
int usedCompletionPortThreads = maxCompletionPortThreads - completionPortThreads;
39+
40+
context.Logger.Log($"Max worker threads: {maxWorkerThreads}");
41+
context.Logger.Log($"Used worker threads: {usedWorkerThreads}");
42+
context.Logger.Log($"Max completion port threads: {maxCompletionPortThreads}");
43+
context.Logger.Log($"Used completion port threads: {usedCompletionPortThreads}");
44+
}
45+
catch
46+
{
47+
//Do nothing
48+
}
49+
}
50+
3051
internal static async void RunNamedPipedServer(RuntimeContext context)
3152
{
3253
PipeSecurity ps = new PipeSecurity();
3354
ps.AddAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.FullControl, AccessControlType.Allow));
3455

3556
context.Logger.Log("Start server");
57+
LogThreadStatus(context);
3658
// FinishTime > DateTime.Nowではなく、trueでも良いが、念のため。
3759
while (!context.IsEndTime)
3860
{
@@ -41,6 +63,7 @@ internal static async void RunNamedPipedServer(RuntimeContext context)
4163
var cancellationTokenSource = new CancellationTokenSource();
4264
Task waitTask = pipeServer.WaitForConnectionAsync(cancellationTokenSource.Token);
4365
TimeSpan waitDuration = context.FinishTime - DateTime.Now;
66+
waitDuration = waitDuration < TimeSpan.Zero ? TimeSpan.Zero : waitDuration;
4467
#pragma warning disable CS4014 // この呼び出しは待機されなかったため、現在のメソッドの実行は呼び出しの完了を待たずに続行されます
4568
Task.Delay(waitDuration).ContinueWith(t => cancellationTokenSource.Cancel());
4669
#pragma warning restore CS4014 // この呼び出しは待機されなかったため、現在のメソッドの実行は呼び出しの完了を待たずに続行されます
@@ -61,7 +84,7 @@ internal static async void RunNamedPipedServer(RuntimeContext context)
6184
}
6285
if (receiveString.ToLowerInvariant().Contains("keep-alive"))
6386
{
64-
context.FinishTime = DateTime.Now.AddMinutes(1);
87+
context.FinishTime = DateTime.Now.AddMinutes(2);
6588
continue;
6689
}
6790
}
@@ -88,7 +111,7 @@ internal static void SendKeepAliveMessage(RuntimeContext context)
88111
{
89112
using (var pipeClient = new NamedPipeClientStream(".", GeneratePipeName(), PipeDirection.Out))
90113
{
91-
pipeClient.Connect(1000);
114+
pipeClient.Connect(15000);
92115
using (var writer = new StreamWriter(pipeClient) { AutoFlush = true })
93116
{
94117
writer.WriteLine("keep-alive");
@@ -99,6 +122,7 @@ internal static void SendKeepAliveMessage(RuntimeContext context)
99122
catch (TimeoutException)
100123
{
101124
context.Logger.Log("Failed to connect to the named pipe server within the timeout period.");
125+
LogThreadStatus(context);
102126
}
103127
catch (Exception ex)
104128
{

RepostConfirmationCanceler/RuntimeContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class RuntimeContext
1919

2020
internal RuntimeContext(RunTimeMode mode)
2121
{
22-
FinishTime = DateTime.Now.AddMinutes(1);
22+
FinishTime = DateTime.Now.AddMinutes(2);
2323
Logger = new Logger(mode);
2424
Config = ConfigLoader.LoadConfig();
2525
}

0 commit comments

Comments
 (0)