hangfire-postgres / Hangfire.PostgreSql

PostgreSql Storage Provider for Hangfire
Other
354 stars 132 forks source link

Error "unsupported Unicode escape sequence" after update #358

Open KolyaNET opened 4 months ago

KolyaNET commented 4 months ago

I had Hangfire.AspNetCore 1.7.36 and Hangfire.PostgreSql 1.19.12. Then I updated to Hangfire.AspNetCore 1.8.12 and Hangfire.PostgreSql 1.20.8 and I get an error.

System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3 | 
Error while executing install/upgrade | 
Npgsql.PostgresException (0x80004005): 22P05: unsupported Unicode escape sequence

DETAIL: \u0000 cannot be converted to text.
   at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()
   at Hangfire.PostgreSql.PostgreSqlObjectsInstaller.Install(NpgsqlConnection connection, String schemaName)
  Exception data:
    Severity: ERROR
    SqlState: 22P05
    MessageText: unsupported Unicode escape sequence
    Detail: \u0000 cannot be converted to text.
    Where: JSON data, line 1: ...ed to the next search result","ExceptionDetails":...
    File: json.c
    Line: 882
    Routine: json_lex_string Severity: ERROR;InvariantSeverity: ERROR;SqlState: 22P05;MessageText: unsupported Unicode escape sequence;Detail: \u0000 cannot be converted to text.;Where: JSON data, line 1: ...ed to the next search result","ExceptionDetails":...;File: json.c;Line: 882;Routine: json_lex_string

I discovered that in the "state" table there is an entry with "name" equal to "Failed". In the "data" column

{
   "FailedAt":"2023-10-31T09:50:10.5272314Z",
   "ExceptionType":"System.InvalidOperationException",
   "ExceptionMessage":"Failed to proceed to the next search result",
   "ExceptionDetails":"System.InvalidOperationException: Failed to proceed to the next search result\n ---> LdapException: Operations Error (1) Operations Error\nLdapException: Server Message: 000004DC: LdapErr: DSID-0C090A71, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v3839\u0000\nLdapException: Matched DN: \n   --- End of inner exception stack trace"
}

The \u0000 character is in the ExceptionDetails line

azygis commented 4 months ago

The fastest way is just sanitizing the existing data before updating. We can do that as well in update scripts for a later version, but that might take a while as I currently have no capacity to do stuff outside of working hours.

Keeping the issue open for when I do find some time to do that.