mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	fix: make sure monotonicTime() value is reasonable (#24518)
				
					
				
			https://github.com/microsoft/playwright/issues/24432
This commit is contained in:
		
							parent
							
								
									d92fe16b76
								
							
						
					
					
						commit
						f135b5f7a8
					
				@ -14,7 +14,19 @@
 | 
				
			|||||||
 * limitations under the License.
 | 
					 * limitations under the License.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The `process.hrtime()` returns a time from some arbitrary
 | 
				
			||||||
 | 
					// date in the past; on certain systems, this is the time from the system boot.
 | 
				
			||||||
 | 
					// The `monotonicTime()` converts this to milliseconds.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// For a Linux server with uptime of 36 days, the `monotonicTime()` value
 | 
				
			||||||
 | 
					// will be 36 * 86400 * 1000 = 3_110_400_000, which is larger than
 | 
				
			||||||
 | 
					// the maximum value that `setTimeout` accepts as an argument: 2_147_483_647.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// To make the `monotonicTime()` a reasonable value, we anchor
 | 
				
			||||||
 | 
					// it to the time of the first import of this utility.
 | 
				
			||||||
 | 
					const initialTime = process.hrtime();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function monotonicTime(): number {
 | 
					export function monotonicTime(): number {
 | 
				
			||||||
  const [seconds, nanoseconds] = process.hrtime();
 | 
					  const [seconds, nanoseconds] = process.hrtime(initialTime);
 | 
				
			||||||
  return seconds * 1000 + (nanoseconds / 1000 | 0) / 1000;
 | 
					  return seconds * 1000 + (nanoseconds / 1000 | 0) / 1000;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user