Question about row locking with InnoDB

Hey guys… I have a couple questions on row locking.

What happens if a script locks some rows but before they are unlocked the script crashes or something?

Also… what actually happens when they are locked… I assume you can still run “SELECT” on them?

Thanks a lot!

let us consider a little tricky problem. Suppose we have a table table_name with index on colx. We will have two queries running in parallel. For sure, both the queries are working on only one row each and as per the application, they are always different queries.
The queries we have are:

1: mysql> SELECT * FROM table_name WHERE

2: -> colx IS NULL

3: -> LIMIT 1

4: -> FOR UPDATE;

and

1: mysql> UPDATE table_name SET

2: -> colx = NULL, coly = NULL

3: -> WHERE colz = ‘something’;

The first query starts locking the index records. But locking is is done record by record. Meanwhile, the second query also gets lock on the record that signifies the current value of colx and proceeds towards the NULL value record. Now by the time second query gets to the NULL value record, that gets locked by the first query and first query somehow waits for the lock already