t3rm1n4l/go-mega

nil deference and crash if retries exceeded

egroenen opened this issue · 1 comments

The following code in mega.go crashes with a nil deference at line 909. I suspect that when the retries are exceeded that rsp is nil, so rsp.Body dies. I check for nil is advised. I'd also advise a sleep within the retry to give the server time to recover.

                            for retry := 0; retry < m.retries+1; retry++ {
                                    rsp, err = client.Do(req)
                                    if err == nil {
                                            if rsp.StatusCode == 200 {
                                                    break
                                            } else {
                                                    rsp.Body.Close()
                                            }
                                    }
                            }

                            chunk_resp, err = ioutil.ReadAll(rsp.Body)
ncw commented

Thanks for the report - I've fixed that now.