Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
Process exit code is zero when server running

I have a test suite, with a Main function that returns 1. However, the exit code after the application terminates is 0.

This seems to be related to a ASP.NET server I'm running in the background. If I disable the server, the exit code is 1 as expected.

This code works as expected, and the console reports an exit code of 1 (this is F# syntax, but I'm pretty sure that's not related):

[<EntryPoint>
let main (arts : string array) : int =
  1

while this has an exit code of 0, which is not what I expect:

[<EntryPoint>
let main (arts : string array) : int =
  MyHttpServer.init()
  1

Here's the MyHttpServer.init function:

let init() : Task =
  Host
     .CreateDefaultBuilder()
     .Build()
     .RunAsync()

My question: what is it about having a server running in the background that is causing the exit code to be zero? Is there something in .NET where the exit code is affected by background tasks and threads?

Note: .NET 6 preview 5, but this has happened on all versions I've used from .NET 5 onwards.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Not super familiar with F# syntax, BUT I suspect that if Init() exits b/c of an error/exception, then execution would never reach the line returning a 1, and would therefore exit with a value of 0.

EDIT: If an exception is thrown when calling Init, or if an exception is thrown before Init can return, the unhandled exception would terminate the process, and the code that returns 1 would not be executed.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!