Error setting system time with real-time clock

I have a DS3231 real-time clock connected to my Beagelbone Black.

I have these lines in /etc/rc.local to initialize the system time from the RTC:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sleep 5
/sbin/hwclock -s -f /dev/rtc1
/sbin/hwclock -w

It almost always works correctly however:
Infrequently at boot up the hwclock commands fail and then the rest of rc.local doesn’t run.
Here’s the error output I captured from rc.local:

hwclock: Timed out waiting for time change.
hwclock: The Hardware Clock does not contain a valid time, so we cannot set the System Time from it.
Unable to set system clock.

Any idea on what could cause this error?

Thanks,
Kirk