From 2d4a7934831c791cfceb1ec7a37a39d4824aeca1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 20 Jul 2022 20:40:50 -0500 Subject: add Dumper --- src/slskd/Common/Dumper.cs | 156 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/slskd/Common/Dumper.cs (limited to 'src') diff --git a/src/slskd/Common/Dumper.cs b/src/slskd/Common/Dumper.cs new file mode 100644 index 00000000..da6ec06c --- /dev/null +++ b/src/slskd/Common/Dumper.cs @@ -0,0 +1,156 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + using System; + using System.Diagnostics; + using System.IO; + using System.Net.Http; + using System.Runtime.InteropServices; + using System.Threading.Tasks; + + /// + /// Dumps the contents of the application's memory to a .dmp file using dotnet-dump. + /// + /// + /// + /// Monitor https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump for tool updates. Currently supported + /// runtime IDs: + /// + /// + /// Currently supported runtime IDs: + /// https://aka.ms/dotnet-dump/win-x86 + /// https://aka.ms/dotnet-dump/win-x64 + /// https://aka.ms/dotnet-dump/win-arm + /// https://aka.ms/dotnet-dump/win-arm64 + /// https://aka.ms/dotnet-dump/osx-x64 + /// https://aka.ms/dotnet-dump/linux-x64 + /// https://aka.ms/dotnet-dump/linux-arm + /// https://aka.ms/dotnet-dump/linux-arm64 + /// https://aka.ms/dotnet-dump/linux-musl-x64 + /// https://aka.ms/dotnet-dump/linux-musl-arm64 + /// + /// + /// + public class Dumper : IDisposable + { + private static readonly string URLTemplate = "https://aka.ms/dotnet-dump/$RID"; + + private string BinFile { get; set; } + private bool Disposed { get; set; } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + public async Task DumpAsync() + { + BinFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + var outputFile = Path.Combine(Path.GetTempPath(), $"slskd_{Path.GetRandomFileName()}.dmp"); + + var url = URLTemplate.Replace("$RID", GetRID()); + + await Download(url, BinFile); + + await ExecAsync(BinFile, Environment.ProcessId, outputFile); + + return outputFile; + } + + protected virtual void Dispose(bool disposing) + { + if (!Disposed) + { + if (disposing) + { + TryDelete(BinFile); + } + + Disposed = true; + } + } + + private async Task Download(string url, string destination) + { + using var http = new HttpClient(); + + using var localStream = new FileStream(destination, FileMode.OpenOrCreate); + using var remoteStream = await http.GetStreamAsync(url); + + await remoteStream.CopyToAsync(localStream); + } + + private async Task ExecAsync(string bin, int pid, string output) + { + using var process = new Process(); + process.StartInfo.FileName = bin; + process.StartInfo.Arguments = $"collect --process-id {pid} --type full --output {output}"; + process.Start(); + await process.WaitForExitAsync(); + } + + private string GetRID() + { + // one of: x86, x64, arm, arm64, wasm, s390x + var arch = RuntimeInformation.ProcessArchitecture.ToString().ToLower(); + + // .RuntimeIdentifier returns a very specific (e.g. win10-x64) RID, and we need a generic one (e.g. win-x64). rather + // than trying to hack this up to derive a generic RID, only inspect this to see if this build targeted musl libc (we + // can't get this any other way) + var isMusl = RuntimeInformation.RuntimeIdentifier.ToLower().Contains("musl"); + + string os = default; + + // seems like there should be a way to just retrieve this, but there is not as of .NET 6 + if (OperatingSystem.IsLinux()) + { + os = "linux"; + } + else if (OperatingSystem.IsWindows()) + { + os = "win"; + } + else if (OperatingSystem.IsMacOS() || OperatingSystem.IsFreeBSD()) + { + os = "osx"; + } + + if (os == default) + { + throw new PlatformNotSupportedException($"Unable to determine operating system. RID is {RuntimeInformation.RuntimeIdentifier}; did someone forget to update Dumper.cs to reflect .NET targeting changes?"); + } + + return $"{os}-{(isMusl ? "musl-" : string.Empty)}{arch}"; + } + + private bool TryDelete(string file) + { + try + { + File.Delete(file); + return true; + } + catch (FileNotFoundException) + { + return false; + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From d52ec889fcf717014e7b29359e56ff15eabd0077 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 20 Jul 2022 20:41:02 -0500 Subject: add endpoint for memory dumps --- src/slskd/Core/API/Controllers/ApplicationController.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index 3cf3c0a3..ac8be802 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -136,5 +136,15 @@ namespace slskd.Core.API return Ok(); } + + [HttpGet("dump")] + [Authorize] + public async Task DumpMemory() + { + using var dumper = new Dumper(); + var file = await dumper.DumpAsync(); + + return PhysicalFile(file, "application/octet-stream", "slskd.dmp"); + } } } -- cgit v1.2.3 From f15487046ab14c0de4ab2562a02dd9467b54703f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 20 Jul 2022 21:39:41 -0500 Subject: chmod bin on linux/mac --- src/slskd/Common/Dumper.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/Dumper.cs b/src/slskd/Common/Dumper.cs index da6ec06c..766fe803 100644 --- a/src/slskd/Common/Dumper.cs +++ b/src/slskd/Common/Dumper.cs @@ -69,7 +69,12 @@ namespace slskd await Download(url, BinFile); - await ExecAsync(BinFile, Environment.ProcessId, outputFile); + if (!OperatingSystem.IsWindows()) + { + await ExecAsync("/bin/sh", $"-c \"chmod +x {BinFile}\""); + } + + await ExecAsync(BinFile, $"collect --process-id {Environment.ProcessId} --type full --output {outputFile}"); return outputFile; } @@ -97,11 +102,11 @@ namespace slskd await remoteStream.CopyToAsync(localStream); } - private async Task ExecAsync(string bin, int pid, string output) + private async Task ExecAsync(string bin, string args) { using var process = new Process(); process.StartInfo.FileName = bin; - process.StartInfo.Arguments = $"collect --process-id {pid} --type full --output {output}"; + process.StartInfo.Arguments = args; process.Start(); await process.WaitForExitAsync(); } -- cgit v1.2.3 From aa2ccff9956dac26125ff9950bfb826d716ffbfa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Jul 2022 06:00:05 +0000 Subject: Bump terser from 5.14.1 to 5.14.2 in /src/web Bumps [terser](https://github.com/terser/terser) from 5.14.1 to 5.14.2. - [Release notes](https://github.com/terser/terser/releases) - [Changelog](https://github.com/terser/terser/blob/master/CHANGELOG.md) - [Commits](https://github.com/terser/terser/commits) --- updated-dependencies: - dependency-name: terser dependency-type: indirect ... Signed-off-by: dependabot[bot] --- src/web/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/web/package-lock.json b/src/web/package-lock.json index 0b277f69..b58cfc3b 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -15384,9 +15384,9 @@ } }, "node_modules/terser": { - "version": "5.14.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.1.tgz", - "integrity": "sha512-+ahUAE+iheqBTDxXhTisdA8hgvbEG1hHOQ9xmNjeUJSoi6DU/gMrKNcfZjHkyY6Alnuyc+ikYJaxxfHkT3+WuQ==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", "dev": true, "dependencies": { "@jridgewell/source-map": "^0.3.2", @@ -28102,9 +28102,9 @@ } }, "terser": { - "version": "5.14.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.1.tgz", - "integrity": "sha512-+ahUAE+iheqBTDxXhTisdA8hgvbEG1hHOQ9xmNjeUJSoi6DU/gMrKNcfZjHkyY6Alnuyc+ikYJaxxfHkT3+WuQ==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", "dev": true, "requires": { "@jridgewell/source-map": "^0.3.2", -- cgit v1.2.3 From 9558ff17faf791414cd153df7053a9e56ab90045 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 21 Jul 2022 20:04:27 -0500 Subject: trap and log errors in delegates --- src/slskd/Application.cs | 192 ++++++++++++++++++++++++++++------------------- 1 file changed, 116 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a307a291..9d7e96ef 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -344,10 +344,18 @@ namespace slskd /// A Task resolving an IEnumerable of Soulseek.Directory. private async Task BrowseResponseResolver(string username, IPEndPoint endpoint) { - var directories = (await Shares.BrowseAsync()) - .Select(d => new Soulseek.Directory(d.Name.Replace('/', '\\'), d.Files)); // Soulseek NS requires backslashes + try + { + var directories = (await Shares.BrowseAsync()) + .Select(d => new Soulseek.Directory(d.Name.Replace('/', '\\'), d.Files)); // Soulseek NS requires backslashes - return new BrowseResponse(directories); + return new BrowseResponse(directories); + } + catch (Exception ex) + { + Log.Warning(ex, "Failed to resolve browse response: {Message}", ex.Message); + throw; + } } private void Client_BrowseProgressUpdated(object sender, BrowseProgressUpdatedEventArgs args) @@ -562,7 +570,7 @@ namespace slskd catch (Exception ex) { Log.Warning(ex, "Failed to estimate place in queue for {Filename} requested by {Username}", filename, username); - return Task.FromResult(null); + throw; } } @@ -576,8 +584,16 @@ namespace slskd /// A Task resolving an instance of Soulseek.Directory containing the contents of the requested directory. private async Task DirectoryContentsResponseResolver(string username, IPEndPoint endpoint, int token, string directory) { - var dir = await Shares.ListDirectoryAsync(directory); - return dir; + try + { + var dir = await Shares.ListDirectoryAsync(directory); + return dir; + } + catch (Exception ex) + { + Log.Warning(ex, "Failed to resolve directory contents: {Message}", ex.Message); + throw; + } } /// @@ -604,65 +620,73 @@ namespace slskd return; } - _ = endpoint; - string localFilename; - FileInfo fileInfo = default; - - Console.WriteLine($"[UPLOAD REQUESTED] [{username}/{filename}]"); - try { - localFilename = (await Shares.ResolveFilenameAsync(filename)).ToLocalOSPath(); + _ = endpoint; + string localFilename; + FileInfo fileInfo = default; - fileInfo = new FileInfo(localFilename); + Console.WriteLine($"[UPLOAD REQUESTED] [{username}/{filename}]"); - if (!fileInfo.Exists) + try { - throw new NotFoundException(); - } - } - catch (NotFoundException) - { - Console.WriteLine($"[UPLOAD REJECTED] File {filename} not found."); - throw new DownloadEnqueueException($"File not shared."); - } + localFilename = (await Shares.ResolveFilenameAsync(filename)).ToLocalOSPath(); - // create a new cancellation token source so that we can cancel the upload from the UI. - var cts = new CancellationTokenSource(); - var topts = new TransferOptions( - stateChanged: (e) => - { - tracker.AddOrUpdate(e.Transfer, cts); + fileInfo = new FileInfo(localFilename); - if (e.Transfer.State.HasFlag(TransferStates.Queued)) + if (!fileInfo.Exists) { - Transfers.Uploads.Queue.Enqueue(e.Transfer); + throw new NotFoundException(); } - }, - progressUpdated: (e) => tracker.AddOrUpdate(e.Transfer, cts), - governor: (tx, req, ct) => Transfers.Uploads.Governor.GetBytesAsync(tx, req, ct), - reporter: (tx, att, grant, act) => Transfers.Uploads.Governor.ReturnBytes(tx, att, grant, act), - slotAwaiter: (tx, ct) => Transfers.Uploads.Queue.AwaitStartAsync(tx), - slotReleased: (tx) => Transfers.Uploads.Queue.Complete(tx)); - - // accept all download requests, and begin the upload immediately. normally there would be an internal queue, and - // uploads would be handled separately. - _ = Task.Run(async () => - { - // users with uploads must be watched so that we can keep informed of their - // online status, privileges, and statistics. this is so that we can accurately - // determine their effective group. - if (!Users.IsWatched(username)) + } + catch (NotFoundException) { - await Users.WatchAsync(username); + Console.WriteLine($"[UPLOAD REJECTED] File {filename} not found."); + throw new DownloadEnqueueException($"File not shared."); } - using var stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read); - await Client.UploadAsync(username, filename, fileInfo.FullName, options: topts, cancellationToken: cts.Token); - }).ContinueWith(t => + // create a new cancellation token source so that we can cancel the upload from the UI. + var cts = new CancellationTokenSource(); + var topts = new TransferOptions( + stateChanged: (e) => + { + tracker.AddOrUpdate(e.Transfer, cts); + + if (e.Transfer.State.HasFlag(TransferStates.Queued)) + { + Transfers.Uploads.Queue.Enqueue(e.Transfer); + } + }, + progressUpdated: (e) => tracker.AddOrUpdate(e.Transfer, cts), + governor: (tx, req, ct) => Transfers.Uploads.Governor.GetBytesAsync(tx, req, ct), + reporter: (tx, att, grant, act) => Transfers.Uploads.Governor.ReturnBytes(tx, att, grant, act), + slotAwaiter: (tx, ct) => Transfers.Uploads.Queue.AwaitStartAsync(tx), + slotReleased: (tx) => Transfers.Uploads.Queue.Complete(tx)); + + // accept all download requests, and begin the upload immediately. normally there would be an internal queue, and + // uploads would be handled separately. + _ = Task.Run(async () => + { + // users with uploads must be watched so that we can keep informed of their + // online status, privileges, and statistics. this is so that we can accurately + // determine their effective group. + if (!Users.IsWatched(username)) + { + await Users.WatchAsync(username); + } + + using var stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read); + await Client.UploadAsync(username, filename, fileInfo.FullName, options: topts, cancellationToken: cts.Token); + }).ContinueWith(t => + { + Console.WriteLine($"[UPLOAD FAILED] {t.Exception}"); + }, TaskContinuationOptions.NotOnRanToCompletion); // fire and forget + } + catch (Exception ex) { - Console.WriteLine($"[UPLOAD FAILED] {t.Exception}"); - }, TaskContinuationOptions.NotOnRanToCompletion); // fire and forget + Log.Warning(ex, "Failed to enqueue upload: {Message}", ex.Message); + throw; + } } private async Task OptionsMonitor_OnChange(Options newOptions) @@ -840,29 +864,37 @@ namespace slskd return null; } - var results = await Shares.SearchAsync(query); - - if (results.Any()) + try { - // make sure our average speed (as reported by the server) is reasonably up to date - await RefreshUserStatistics(); + var results = await Shares.SearchAsync(query); - var forecastedPosition = Transfers.Uploads.Queue.ForecastPosition(username); + if (results.Any()) + { + // make sure our average speed (as reported by the server) is reasonably up to date + await RefreshUserStatistics(); - Console.WriteLine($"[SENDING SEARCH RESULTS]: {results.Count()} records to {username} for query {query.SearchText} (forecasted position: {forecastedPosition})"); + var forecastedPosition = Transfers.Uploads.Queue.ForecastPosition(username); - return new SearchResponse( - Client.Username, - token, - uploadSpeed: State.CurrentValue.User.Statistics.AverageSpeed, - freeUploadSlots: forecastedPosition == 0 ? 1 : 0, - queueLength: forecastedPosition, - fileList: results); - } + Console.WriteLine($"[SENDING SEARCH RESULTS]: {results.Count()} records to {username} for query {query.SearchText} (forecasted position: {forecastedPosition})"); - // if no results, either return null or an instance of SearchResponse with a fileList of length 0 in either case, no - // response will be sent to the requestor. - return null; + return new SearchResponse( + Client.Username, + token, + uploadSpeed: State.CurrentValue.User.Statistics.AverageSpeed, + freeUploadSlots: forecastedPosition == 0 ? 1 : 0, + queueLength: forecastedPosition, + fileList: results); + } + + // if no results, either return null or an instance of SearchResponse with a fileList of length 0 in either case, no + // response will be sent to the requestor. + return null; + } + catch (Exception ex) + { + Log.Warning(ex, "Failed to resolve search response: {Message}", ex.Message); + throw; + } } private void ShareState_OnChange((ShareState Previous, ShareState Current) state) @@ -926,13 +958,21 @@ namespace slskd /// A Task resolving the UserInfo instance. private Task UserInfoResolver(string username, IPEndPoint endpoint) { - var info = new UserInfo( - description: Options.Soulseek.Description, - uploadSlots: 1, - queueLength: 0, - hasFreeUploadSlot: false); + try + { + var info = new UserInfo( + description: Options.Soulseek.Description, + uploadSlots: 1, + queueLength: 0, + hasFreeUploadSlot: false); - return Task.FromResult(info); + return Task.FromResult(info); + } + catch (Exception ex) + { + Log.Warning(ex, "Failed to resolve user info: {Message}", ex.Message); + throw; + } } } } -- cgit v1.2.3 From 6934fd27435923ef267de37438dd6c30e72b0793 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 23 Jul 2022 15:03:39 -0500 Subject: remove console logging --- src/slskd/Application.cs | 20 +++++++++----------- src/slskd/Common/Logging/ConsoleWriteLineLogger.cs | 9 ++++++++- src/slskd/Program.cs | 9 ++++++++- 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 9d7e96ef..a2598d1e 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -124,10 +124,10 @@ namespace slskd Client.UserStatusChanged += Client_UserStatusChanged; Client.PrivateMessageReceived += Client_PrivateMessageRecieved; - Client.PrivateRoomMembershipAdded += (e, room) => Console.WriteLine($"Added to private room {room}"); - Client.PrivateRoomMembershipRemoved += (e, room) => Console.WriteLine($"Removed from private room {room}"); - Client.PrivateRoomModerationAdded += (e, room) => Console.WriteLine($"Promoted to moderator in private room {room}"); - Client.PrivateRoomModerationRemoved += (e, room) => Console.WriteLine($"Demoted from moderator in private room {room}"); + Client.PrivateRoomMembershipAdded += (e, room) => Log.Information("Added to private room {Room}", room); + Client.PrivateRoomMembershipRemoved += (e, room) => Log.Information("Removed from private room {Room}", room); + Client.PrivateRoomModerationAdded += (e, room) => Log.Information("Promoted to moderator in private room {Room}", room); + Client.PrivateRoomModerationRemoved += (e, room) => Log.Information("Demoted from moderator in private room {Room}", room); Client.PublicChatMessageReceived += Client_PublicChatMessageReceived; Client.RoomMessageReceived += Client_RoomMessageReceived; @@ -464,14 +464,13 @@ namespace slskd if (Options.Integration.Pushbullet.Enabled && !args.Replayed) { - Console.WriteLine("Pushing..."); _ = Pushbullet.PushAsync($"Private Message from {args.Username}", args.Username, args.Message); } } private void Client_PublicChatMessageReceived(object sender, PublicChatMessageReceivedEventArgs args) { - Console.WriteLine($"[PUBLIC CHAT] [{args.RoomName}] [{args.Username}]: {args.Message}"); + Log.Information("[Public Chat/{Room}] [{Username}]: {Message}", args.RoomName, args.Username, args.Message); if (Options.Integration.Pushbullet.Enabled && args.Message.Contains(Client.Username)) { @@ -557,7 +556,6 @@ namespace slskd private void Client_UserStatusChanged(object sender, UserStatus args) { - Console.WriteLine($"[USER] {args.Username}: {args.Presence}"); } private Task PlaceInQueueResolver(string username, IPEndPoint endpoint, string filename) @@ -626,7 +624,7 @@ namespace slskd string localFilename; FileInfo fileInfo = default; - Console.WriteLine($"[UPLOAD REQUESTED] [{username}/{filename}]"); + Log.Information("[{Context}] {Username} requested {Filename}]", "UPLOAD REQUESTED", username, filename); try { @@ -641,7 +639,7 @@ namespace slskd } catch (NotFoundException) { - Console.WriteLine($"[UPLOAD REJECTED] File {filename} not found."); + Log.Information("[{Context}] {Filename} for {Username}: file not found", "UPLOAD REJECTED", username, filename); throw new DownloadEnqueueException($"File not shared."); } @@ -679,7 +677,7 @@ namespace slskd await Client.UploadAsync(username, filename, fileInfo.FullName, options: topts, cancellationToken: cts.Token); }).ContinueWith(t => { - Console.WriteLine($"[UPLOAD FAILED] {t.Exception}"); + Log.Information("[{Context}] {Filename} for {Username}: {Message}", "UPLOAD FAILED", username, filename, t.Exception?.Message); }, TaskContinuationOptions.NotOnRanToCompletion); // fire and forget } catch (Exception ex) @@ -875,7 +873,7 @@ namespace slskd var forecastedPosition = Transfers.Uploads.Queue.ForecastPosition(username); - Console.WriteLine($"[SENDING SEARCH RESULTS]: {results.Count()} records to {username} for query {query.SearchText} (forecasted position: {forecastedPosition})"); + Log.Information("[{Context}]: Sending {Count} records to {Username} for query '{Query}'", "SEARCH RESULT SENT", results.Count(), username, query.SearchText); return new SearchResponse( Client.Username, diff --git a/src/slskd/Common/Logging/ConsoleWriteLineLogger.cs b/src/slskd/Common/Logging/ConsoleWriteLineLogger.cs index 4e829df6..d7904b7a 100644 --- a/src/slskd/Common/Logging/ConsoleWriteLineLogger.cs +++ b/src/slskd/Common/Logging/ConsoleWriteLineLogger.cs @@ -28,7 +28,14 @@ namespace slskd /// public void Write(LogEvent logEvent) { - Console.WriteLine(logEvent.RenderMessage()); + try + { + Console.WriteLine(logEvent.RenderMessage()); + } + catch + { + // noop. console may not be available in all cases. + } } } } diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index ae4f2015..f11132b4 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -991,7 +991,14 @@ namespace slskd banner += "\n└────────────────────────────────────────────────────────┘"; - Console.WriteLine(banner); + try + { + Console.WriteLine(banner); + } + catch + { + // noop. console may not be available in all cases. + } } private static void VerifyDirectory(string directory, bool createIfMissing = true, bool verifyWriteable = true) -- cgit v1.2.3