I'm not sure this is a good solution. At least in the previous code, the recursive solution had a failure case where the task would fail and execution would cease (even if it was indeterminate). Now, theoretically, the task could run forever and never finish if the remote server does not return an expected response.
Confluence and JIRA generally give plugins a grace period of 60 seconds to finish enabling. I think 1-2 minutes for the task timeout would be appropriate. I can implement this if you are stretched for time; just let me know.
I'm saying that you probably can't guarantee that the remote server will ever return a HTTP error code. It may continue to perpetually return HTTP 200 OK responses to indicate that the plugin is still "installing". This seems to be what was happening in the current failing build - the remote server spent 8 minutes telling the client to keep polling before the task overflowed the stack.