led1.setColor(BLUE) fails when app closed

What you’ve described sounds sufficiently similar to this:

to be worth investigating

and the reason I asked about your ESP core was because of this:

but as you’re using an ESP32 based board then it would be your ESP32 core you’d need to look at.

Pete.