The error would place an entry into your Roundcube error log, if there is nothing there then check the permissions on the logs directory to ensure the webserver user can write to it.
Is it possible there is some kind of connection throttling being used to protect your IMAP server - it is just a guess but something like that might explain the random nature of the error.