It happens completely at random times, one time it will work and other times it will give this error. I searched the error on Google, and it seems like it's happening with a lot of people in diff parts of code where they interact with workers locally, and it's still not resolved.
I have tried using the Rest API too for the same, but still get this error at random times.