Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

User directory background process gets stuck when someone sets a name with a null codepoint #12755

Closed
DMRobertson opened this issue May 17, 2022 · 1 comment · Fixed by #12762
Assignees
Labels
A-User-Directory S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@DMRobertson
Copy link
Contributor

DMRobertson commented May 17, 2022

Reported by @Fizzadar via #12743 and @andrewsh via chat.

An event that looks like this:

{
    "content":
    {
        "displayname": "\u0001VERSION\u0001\u0000",
        "membership": "join"
    }
}

Causes an exception updating the user directory table A string literal cannot contain NUL (0x00) characters which never passes and just keeps retrying consuming a lot of CPU on main.

2022-05-17 11:18:34,417 - synapse.metrics.background_process_metrics - 245 - ERROR - user_directory.notify_new_event-2101 - Background process 'user_directory.notify_new_event' threw an exception
Traceback (most recent call last):                                                                                                                                                                                                             
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/metrics/background_process_metrics.py", line 243, in run
    return await func(*args, **kwargs)                                                                                                                                                                                                         
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/handlers/user_directory.py", line 119, in process 
    await self._unsafe_process()                                                                                                                                                                                                               
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/handlers/user_directory.py", line 182, in _unsafe_process
    await self._handle_deltas(deltas)                                                                                                                                                                                                          
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/handlers/user_directory.py", line 211, in _handle_deltas
    await self._handle_room_membership_event(                                                                                                                                                                                                  
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/handlers/user_directory.py", line 348, in _handle_room_membership_event
    await self._handle_possible_remote_profile_change(                                                                                                                                                                                         
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/handlers/user_directory.py", line 478, in _handle_possible_remote_profile_change
    await self.store.update_profile_in_user_dir(user_id, new_name, new_avatar)                                                                                                                                                                 
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/databases/main/user_directory.py", line 522, in update_profile_in_user_dir
    await self.db_pool.runInteraction(                                                                                                                                                                                                         
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 814, in runInteraction 
    return await delay_cancellation(_runInteraction())                                                                                                                                                                                         
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/internet/defer.py", line 1656, in _inlineCallbacks
    result = current_context.run(                                                                                                                                                                                                              
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/failure.py", line 514, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)                                                                                                                                                                                             
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 786, in _runInteraction
    result = await self.runWithConnection(                                                                                                                                                                                                     
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 909, in runWithConnection
    return await make_deferred_yieldable(                                                                              
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/threadpool.py", line 244, in inContext
    result = inContext.theWork()  # type: ignore[attr-defined]                                                    
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/threadpool.py", line 260, in <lambda>
    inContext.theWork = lambda: context.call(  # type: ignore[attr-defined]                                           
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/context.py", line 117, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)                                             
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/context.py", line 82, in callWithContext
    return func(*args, **kw)                                                                                                                                                                                                                   
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/enterprise/adbapi.py", line 282, in _runWithConnection
    result = func(conn, *args, **kw)                                                                                   
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 902, in inner_func
    return func(db_conn, *args, **kwargs)                                                                                                                                                                                                      
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 650, in new_transaction
    r = func(cursor, *args, **kwargs)                                                                                                                                                                                                          
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/databases/main/user_directory.py", line 479, in _update_profile_in_user_dir_txn
    self.db_pool.simple_upsert_txn(                                                                                                                                                                                                            
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 1150, in simple_upsert_txn
    return self.simple_upsert_txn_native_upsert(                                                                                                                                                                                               
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 1276, in simple_upsert_txn_native_upsert
    txn.execute(sql, list(allvalues.values()))                                                                         
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 337, in execute
    self._do_execute(self.txn.execute, sql, *args)                                                                     
  File "/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/storage/database.py", line 379, in _do_execute
    return func(sql, *args, **kwargs)                                                                                  
ValueError: A string literal cannot contain NUL (0x00) characters.
@DMRobertson DMRobertson added A-User-Directory S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels May 17, 2022
@DMRobertson DMRobertson self-assigned this May 17, 2022
@DMRobertson
Copy link
Contributor Author

@erikjohnston suggests that we treat displaynames containing null codepoints as if there wasn't a displayname to begin with. I'll try to setup a PR for this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-User-Directory S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
1 participant