Ah, now I know why I have this check here. You can call halfClose() in a closed socked. In this case, you are suppose to ignore and keep the closed status. So the code is correct (maybe I should clarify with a comment).