diff --git a/src/auth/oauth.rs b/src/auth/oauth.rs index dcb4f93..47976e8 100644 --- a/src/auth/oauth.rs +++ b/src/auth/oauth.rs @@ -756,6 +756,7 @@ pub async fn process_oauth_code( // 계정 저장 - 재시도 로직 포함 let mut retry_count = 0; let max_retries = 3; + let mut account_created = false; while retry_count < max_retries { match oauth_service.storage.create_account(&new_account).await { @@ -764,6 +765,7 @@ pub async fn process_oauth_code( "✅ New account created successfully: account_hash={}", account_hash ); + account_created = true; // 계정 생성 확인 match oauth_service @@ -778,6 +780,7 @@ pub async fn process_oauth_code( error!( "⚠️ Account not found after creation - may be a database sync issue" ); + account_created = false; } Err(e) => { error!("⚠️ Error verifying account creation: {}", e); @@ -796,6 +799,7 @@ pub async fn process_oauth_code( // Duplicate entry 에러인 경우 재시도하지 않음 if e.to_string().contains("Duplicate") { info!("ℹ️ Account may already exist, proceeding anyway"); + account_created = true; // Duplicate는 계정이 이미 존재한다는 의미 break; } @@ -803,11 +807,25 @@ pub async fn process_oauth_code( if retry_count < max_retries { // 짧은 대기 후 재시도 tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; + } else { + // 최대 재시도 횟수 초과 + return Err(AuthError::DatabaseError(format!( + "Failed to create account after {} retries: {}", + max_retries, e + ))); } } } } + // 계정 생성 실패 확인 + if !account_created { + return Err(AuthError::DatabaseError(format!( + "Account creation failed but no error was returned. This should not happen. account_hash={}", + account_hash + ))); + } + new_account }; diff --git a/src/storage/mysql_account.rs b/src/storage/mysql_account.rs index 0fc1757..1be2f76 100644 --- a/src/storage/mysql_account.rs +++ b/src/storage/mysql_account.rs @@ -77,6 +77,9 @@ impl MySqlAccountExt for MySqlStorage { Ok(_) => { info!("✅ Transaction committed successfully"); + // 약간의 대기 시간을 추가하여 데이터베이스 트리거 완료 대기 + tokio::time::sleep(tokio::time::Duration::from_millis(50)).await; + // 새로운 연결을 사용하여 데이터베이스에 실제로 저장되었는지 확인 match sqlx::query_as::<_, (String, String, String, String, i64, i64, i64, bool)>( r#"SELECT account_hash, email, name, id, created_at, updated_at, last_login, is_active FROM accounts WHERE account_hash = ?"# @@ -88,12 +91,22 @@ impl MySqlAccountExt for MySqlStorage { info!("✅ Verified account exists in database with explicit query"); info!("✅ Account details: hash={}, email={}, name={}, id={}, created_at={}, updated_at={}, last_login={}, is_active={}", db_hash, db_email, db_name, db_id, db_created, db_updated, db_login, db_active); + return Ok(()); }, Ok(None) => { - error!("❌ Account not found in database after creation: account_hash={}", account.account_hash); + error!("❌ Account not found in database after creation and commit: account_hash={}", account.account_hash); + error!("❌ This likely means the database trigger failed and rolled back the transaction"); + return Err(StorageError::Database(format!( + "Account not found after creation - trigger may have failed. account_hash={}", + account.account_hash + ))); }, Err(e) => { error!("❌ Failed to verify account creation: {}", e); + return Err(StorageError::Database(format!( + "Failed to verify account creation: {}", + e + ))); } } } @@ -107,8 +120,6 @@ impl MySqlAccountExt for MySqlStorage { ))); } } - - return Ok(()); } Err(e) => { error!("❌ Failed to insert account into database: {}", e);