AWS driver: initDB fails with MySQL 1205 while a running instance holds coordination-row locks across S3/witness I/O

Open
#1,207 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
aws, go, mysql

Research direction

Start in storage/aws/aws.go at mySQLSequencer.initDB, around L1018 and L1040–1060, then trace publishCheckpoint and consumeEntries where FOR UPDATE spans f(...). Reproduce with two instances and delayed S3 or witness I/O; done means a second NewAppender no longer times out with MySQL 1205 while the first instance is active.

Written by the indexing model from the issue text.

Description

Summary

With the AWS storage driver, a new process can fail to start while another instance of the same log is running, whenever that instance's S3 or witness I/O is slow. The new process's initDB blocks on coordination-table row locks that the running instance holds FOR UPDATE across network I/O. After InnoDB's lock wait (innodb_lock_wait_timeout, 50s by default), NewAppender fails with:

failed to init appender lifecycle: failed to create MySQL sequencer: failed to initDB: Error 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

Observed on v1.0.3. The relevant code is unchanged on v1.0.4 and on main.

Mechanism (storage/aws/aws.go)

At every startup, mySQLSequencer.initDB does two things (main, around L1018 and L1040–1060):

  • ALTER TABLE PubCoord ADD COLUMN size ..., expecting ER_DUP_FIELDNAME;
  • INSERT IGNORE INTO each coordination table (Tessera, SeqCoord, IntCoord, PubCoord, GCCoord).

The INSERT IGNORE on an existing row takes a lock on that row, and the ALTER TABLE needs a metadata lock on PubCoord.

Running instances hold those rows FOR UPDATE while calling out:

  • publishCheckpoint takes SELECT publishedAt, size FROM PubCoord WHERE id = ? FOR UPDATE, then runs f(ctx, fromSeq, rootHash) before commit. That call builds, signs and witnesses the checkpoint and writes it to object storage.
  • consumeEntries takes SELECT seq, rootHash FROM IntCoord WHERE id = ? FOR UPDATE (plus Seq ... FOR UPDATE), then runs f(ctx, fromSeq, entries), which integrates and writes tiles and bundles to object storage, before commit.

So any stall in that I/O extends the lock hold, and a starting instance's initDB waits on it. In our case, S3 requests were being rejected with RequestTimeTooSkewed for about 15 minutes. Every new instance started during that window failed with 1205 and crash-looped until the I/O recovered.

Repro sketch

  1. Run one instance of a log on the AWS driver, with a steady trickle of Adds so that integration and publication run.
  2. Make object-storage writes slow, for example by injecting delay into the S3 client or at the network. The goal is for the f(...) inside consumeEntries/publishCheckpoint to take longer than innodb_lock_wait_timeout.
  3. Start a second instance against the same DB. NewAppender returns the 1205 error above after about 50s.

Suggestions (either would fix it for us)

  • Make initDB lock-free when the schema already exists. Check information_schema.COLUMNS before the ALTER TABLE. Replace the unconditional INSERT IGNOREs with a read (SELECT 1 ... WHERE id = 0, which needs no row lock under InnoDB consistent reads), and insert only when the row is missing. Then a started instance never contends with a running one.
  • Or release the coordination row locks before the network I/O, for example with an optimistic compare-and-set on the row after f() completes, so the lock span is bounded by DB latency rather than object-storage or witness latency. That is a bigger change, but it would also bound contention between concurrent running instances.

We're working around it downstream by retrying NewAppender on 1205 with a short backoff. That only helps if the lock clears within the caller's startup budget. Happy to test a fix.

Dominant language
Go
Stars
262
Forks
64
Avg merge
1d 6h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from transparency-dev/tessera

All issues in transparency-dev/tessera

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.