[crac] RFR: 8371462: [CRaC] Improve listening socket reopen through FD policies [v2]

Radim Vansa rvansa at openjdk.org
Thu Nov 13 09:06:00 UTC 2025


On Wed, 12 Nov 2025 11:08:03 GMT, mazhen <duke at openjdk.org> wrote:

>> Radim Vansa has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Disable selector test on Linux
>
> I wanted to share a thought on the current implementation. 
> 
> The present design affects all SelectionKey cancel operations, not just CRaC scenarios.
> 
> An alternative worth considering would be to relocate the reopen callback registration logic into `ServerSocketChannelImpl.closeBeforeCheckpoint()`.  This method lives squarely within the CRaC lifecycle, making it a more natural home for such operations. Just before the channel closes, we could iterate through its associated SelectionKeys and register the necessary restoration callbacks:   
> 
> 
> // In ServerSocketChannelImpl.closeBeforeCheckpoint()                                                                                                                                                          
> @Override                                                                                                                                                                                                      
> protected void closeBeforeCheckpoint() throws IOException {                                                                                                                                                    
>     // Register reopen callbacks for all associated keys before closing                                                                                                                                        
>     forEach(key -> {                                                                                                                                                                                        
>         if (key instanceof SelectionKeyImpl ski && ski.isValid()) {                                                                                                                                            
>             Consumer<Runnable> enqueue = JDKSocketResourceBase.reopenQueue(this);                                                                                                                              
>             if (enqueue != null) {                                                                                                                                                                             
>                 enqueue.accept(() -> {                                                                                                                                                                         
>                       //  Reopen logic: revalidate key, re-register with selector, et...

@mz1999 As you noticed, we would need to somehow expose `AbstractSelectableChannel.forEach` - I would be very careful about changing a visibility of a method in a public class (in a public package). That could be a breaking change if an inheriting class already has such method. We could make that package-private and access that through `SharedSecrets`, though. And I wanted to avoid extra method if I could avoid it - the overhead in `cancel()` of checking a key in an empty CHM seemed acceptable, for non-CRaC scenarios.

I can try how your approach looks like, though.

-------------

PR Comment: https://git.openjdk.org/crac/pull/275#issuecomment-3526598500


More information about the crac-dev mailing list