Bug 65307

Summary: Rewrite and improvements of mod_unique_id
Product: Apache httpd-2 Reporter: Atle Solbakken <atle>
Component: mod_unique_idAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: NEW ---    
Severity: enhancement    
Priority: P2    
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Diff for mod_unique_id.c

Description Atle Solbakken 2021-05-14 16:25:07 UTC
Created attachment 37862 [details]
Diff for mod_unique_id.c

Hi

I've been working on some cleanups in mod_unique_id module and have also changed the composition of values used to ensure unique IDs.

There has recently there has been a bug report #65159 which was resolved by replacing a global counter with a per-thread counter. This is however not enough to ensure uniqueness in all situations.

The cleanup is mostly done because the current module has been patched multiple times over the years and it was kind of messy and difficult to work with.

I'm proposing new data to include in the unique ID string:

- 32 bit process ID
- 64 bit thread ID
- 64 bit timestamp in microseconds
- 16 bit server ID
- 16 bit counter

The server ID is by default 0 but can be set to a fixed value in the configuration. This way an ID can be assigned to different servers for instance when doing load balancing with a common backend.

The 16 bit counter is per-thread (as in the previous patch) and ensures uniqueness should the timestamp be the same in two requests.

There are no random numbers.

All values are swapped to network byte order.

The total length of the unique string has been increased from 27 to 32 characters.

It is nevertheless easy with this patch to change the actual composition of values in the unique ID and I reckon there might be different opinions on this.

The attached diff changes the whole file, it might be easier to read the file whole itself:

https://github.com/apache/httpd/blob/a477b27e2fc74b1a41f8e600c599d89454a5cd38/modules/metadata/mod_unique_id.c

Best regards
Atle