Apadmi-Engineering / Mockzilla

MIT License
29 stars 8 forks source link

Better handling of port conflicts #246

Open TomRHandcock opened 4 days ago

TomRHandcock commented 4 days ago

The Mockzilla server can't listen to a port that is already reserved by another process for obvious reasons. In such cases, Ktor [which runs the server under the hood] throws an exception as there isn't really much else it can do that wouldn't involve unexpected/unwanted behaviour (i.e. changing to an unreserved port which might go unnoticed by an end user). This error is not visible in the Flutter logs surfaced in Android Studio or VS code.

The frequency of this issue is likely to be higher for folks that use iOS simulators as they punch through to the host systems network which may have tooling running on the same port.

This issue is to enhance handling of these exceptions in the Dart layer to print a nice error to the Flutter logs that can be understood by an end user without knowledge of the implementation details of the mockzilla package.

TomRHandcock commented 2 days ago

It appears that although we can catch the java.net.BindException that is thrown upon trying to reuse a reserved port in the mockzilla_android Android source, the application process is terminating before even Kotlin can execute any statements in the catch handler.

Either this is a defect in the ktor package which can hopefully be resolved or we will need to manually check if the desired port is reserved in the KMM package before attempting to start the mock server.