I'm building a program that archives (records to disk) Icecast/Shoutcast streams.
However, there are two problems:
1. If a remote Icecast/Shoutcast stream goes down (for a while), then sometimes the local archiver fails to reconnect after a few reconnection attempts, and gets stuck until I restart the Node.js process.
2. Also, the Node.js streams that are active sometimes get mixed up in a really strange way. For example, Stream A will write to Stream B's disk area, so that the resulting file contains data from the wrong stream. It seems like a bug in Node.js itself, but maybe not. Even if so, it still needs to be handled somehow.
These two problems may be related. For example, there could be an internal limit to the number of concurrent streams that you can have in Node.js, and after a few reconnections it runs out (since the code doesn't delete the previous streams) and then it stops reconnecting, and starts mixing up streams.
I need someone to:
1. Fix these two problems in a robust, solid way, so that all of the possible error states that cause these problems are handled in a clear and concise way.
2. Explain to me why this is happening, so that I won't write code that does this again.
Thanks, and good luck.