(TWILL-110) added state guard to prevent possible race-condition

As described in JIRA, the race-condition can cause deadlock.