Skip to content

fix enlarged error redaction #52364

Closed
@xhebox

Description

Bug Report

ref #51306

Errors of errStrForLog, handleAssertionFailure is already redacted, and we should not redact it again.

tidb/pkg/server/conn.go

Lines 1166 to 1181 in d2eb902

func errStrForLog(err error, redactMode string) string {
if redactMode == errors.RedactLogEnable {
// currently, only ErrParse is considered when enableRedactLog because it may contain sensitive information like
// password or accesskey
if parser.ErrParse.Equal(err) {
return "fail to parse SQL and can't redact when enable log redaction"
}
}
var ret string
if kv.ErrKeyExists.Equal(err) || parser.ErrParse.Equal(err) || infoschema.ErrTableNotExists.Equal(err) {
// Do not log stack for duplicated entry error.
ret = err.Error()
} else {
ret = errors.ErrorStack(err)
}
return redact.String(redactMode, ret)

1. Minimal reproduce step (Required)

mysql> create table t (a int, unique key (a));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1),(1);
ERROR 1062 (23000): Duplicate entry '1' for key 'a'
mysql> set @@session.tidb_redact_log=1;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1),(1);
ERROR 1062 (23000): Duplicate entry '?' for key '?'

2. What did you expect to see? (Required)

[2024/04/07 11:09:34.014 +08:00] [INFO] [conn.go:1147] ["command dispatched failed"] [conn=2097154] [session_alias=] [connInfo="id:2097154, addr:[::1]:46506 status:10, collation:utf8mb4_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into `t` values ( ‹1› ) , ( ‹1› )"] [txn_mode=PESSIMISTIC] [timestamp=448910950141526016] [err="[kv:1062]Duplicate entry '‹1›' for key 't.a'"]

3. What did you see instead (Required)

[2024/04/07 11:09:34.014 +08:00] [INFO] [conn.go:1147] ["command dispatched failed"] [conn=2097154] [session_alias=] [connInfo="id:2097154, addr:[::1]:46506 status:10, collation:utf8mb4_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into `t` values ( ‹1› ) , ( ‹1› )"] [txn_mode=PESSIMISTIC] [timestamp=448910950141526016] [err="‹[kv:1062]Duplicate entry '‹‹1››' for key 't.a'›"]

4. What is your TiDB version? (Required)

master

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions