[MDEV-28178] Windows : sporadic ER_ERROR_ON_RENAME .. (errno: 13 "Permission denied") with Windows Defender Created: 2022-03-27  Updated: 2023-08-12  Resolved: 2022-03-28

Status: Closed
Project: MariaDB Server
Component/s: Platform Windows, Server
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4, 10.8.3, 10.9.1

Type: Bug Priority: Major
Reporter: Vladislav Vaintroub Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
PartOf
is part of MDEV-30162 Fix occasional "Permission denied" on... Closed

 Description   

E:\server\bld\mysql-test> perl .\mysql-test-run.pl innodb.instant_alter_limit --parallel=5
Found handle.exe version 4.22
Logging: E:/server/mysql-test/mariadb-test-run.pl  innodb.instant_alter_limit --parallel=5
VS config: Debug
vardir: E:/server/bld/mysql-test/var
Checking leftover processes...
Removing old var directory...
Creating var directory 'E:/server/bld/mysql-test/var'...
Checking supported features...
MariaDB Version 10.6.8-MariaDB-debug
 - SSL connections supported
 - binaries are debug compiled
Collecting tests...
Installing system database...
 
==============================================================================
 
TEST                                  WORKER RESULT   TIME (ms) or COMMENT
--------------------------------------------------------------------------
 
worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019
worker[2] Using MTR_BUILD_THREAD 301, with reserved ports 16020..16039
worker[3] Using MTR_BUILD_THREAD 302, with reserved ports 16040..16059
worker[4] Using MTR_BUILD_THREAD 303, with reserved ports 16060..16079
worker[5] Using MTR_BUILD_THREAD 304, with reserved ports 16080..16099
innodb.instant_alter_limit '64k,innodb'  w2 [ fail ]
        Test ended at 2022-03-25 14:22:20
 
CURRENT_TEST: innodb.instant_alter_limit
mysqltest: At line 19: query 'ALTER TABLE t DROP b, DROP c, DROP d, DROP e,
ADD COLUMN b INT FIRST, ADD COLUMN c INT, ADD COLUMN d INT AFTER b,
ADD COLUMN e INT AFTER c, ALGORITHM=INSTANT' failed: ER_ERROR_ON_RENAME (1025): Error on rename of '.\test\#sql-alter-2db4-4' to '.\test\t' (errno: 13 "Permission denied")
 
The result from queries just before the failure was:
SET @old_instant=
(SELECT variable_value FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column');
CREATE TABLE t(a INT PRIMARY KEY, b INT, c INT, d INT, e INT)
ENGINE=InnoDB;
INSERT INTO t VALUES(1,2,3,4,5);
SET innodb_strict_mode = OFF;
 
 - saving 'E:/server/bld/mysql-test/var/2/log/innodb.instant_alter_limit-64k,innodb/' to 'E:/server/bld/mysql-test/var/log/innodb.instant_alter_limit-64k,innodb/'
 
Only  1  of 5 completed.



 Comments   
Comment by Alexander Miloslavskiy [ 2023-08-08 ]

I encountered this (now fixed) problem in `REPAIR TABLE` for MYISAM in 10.5.12.
It caused the table to become completely empty:

1) `prepare_for_repair()` renames `TABLE.MYD` to something like `TABLE.MYD-344_241`
2) `prepare_for_repair()` creates a new empty `TABLE.MYD`
3) `prepare_for_repair()` renames (with replacing) `TABLE.MYD-344_241` back into `TABLE.MYD`
4) At the same time, 3rd program does a mere `GetFileAttributesExW()` on `TABLE.MYD`
5) `MoveFile()` fails with `ERROR_ACCESS_DENIED`
6) Empty `TABLE.MYD` remains in place
7) Table is now permanently empty

In this scenario, "bad bad antivirus" "that uses wrong file sharing" is not involved.
Rather, it only requires a curious program that calls `GetFileAttributesExW()` on new files.

Comment by Vladislav Vaintroub [ 2023-08-08 ]

Whether it's a bad antivirus, or an allegedly harmless curious program that opens a file without FILE_SHARE_DELETE, using either a CreateFile or any other api that calls CreateFile internally, such as GetfileAttributesExW, that does not really matter. If a third party program snoops in the directories it does not own, it better does so with extreme care. Which for the allegedly harmless curious program might mean for example opening file yourself with full sharing, and use lightly documented NtQueryInformationFile, instead of GetFileAttributesExW. Otherwise curious program might disturb your db.

Comment by Alexander Miloslavskiy [ 2023-08-12 ]

I don't advocate for the curious program.
I merely wanted to shed some additional light on how this problem may be developing.

Comment by Alexander Miloslavskiy [ 2023-08-12 ]

Frankly I also blamed antivirus initially. I even uninstalled it to make sure.

Generated at Thu Feb 08 09:58:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.