@@ -263,6 +263,7 @@ ucs_status_t ucp_worker_create_ep(ucp_worker_h worker, unsigned ep_init_flags,
263263                                  const  char  * peer_name , const  char  * message ,
264264                                  ucp_ep_h  * ep_p )
265265{
266+     ucp_context_h  context  =  worker -> context ;
266267    ucs_status_t  status ;
267268    ucp_ep_h  ep ;
268269
@@ -271,10 +272,14 @@ ucs_status_t ucp_worker_create_ep(ucp_worker_h worker, unsigned ep_init_flags,
271272        goto err ;
272273    }
273274
274-     if  ((worker -> context -> config .ext .proto_indirect_id  ==  UCS_CONFIG_ON ) || 
275-         ((worker -> context -> config .ext .proto_indirect_id  ==  UCS_CONFIG_AUTO ) && 
276-          (ep_init_flags  &  UCP_EP_INIT_ERR_MODE_PEER_FAILURE ) && 
277-          !(ep_init_flags  &  UCP_EP_INIT_FLAG_MEM_TYPE ))) {
275+     if  (ep_init_flags  &  UCP_EP_INIT_FLAG_MEM_TYPE ) {
276+         ucp_ep_update_flags (ep , UCP_EP_FLAG_INTERNAL , 0 );
277+         goto out ;
278+     }
279+ 
280+     if  ((context -> config .ext .proto_indirect_id  ==  UCS_CONFIG_ON ) || 
281+         ((context -> config .ext .proto_indirect_id  ==  UCS_CONFIG_AUTO ) && 
282+          (ep_init_flags  &  UCP_EP_INIT_ERR_MODE_PEER_FAILURE ))) {
278283        ucp_ep_update_flags (ep , UCP_EP_FLAG_INDIRECT_ID , 0 );
279284    }
280285
@@ -285,14 +290,10 @@ ucs_status_t ucp_worker_create_ep(ucp_worker_h worker, unsigned ep_init_flags,
285290        goto err_destroy_ep_base ;
286291    }
287292
288-     if  (ep_init_flags  &  UCP_EP_INIT_FLAG_MEM_TYPE ) {
289-         ucp_ep_update_flags (ep , UCP_EP_FLAG_INTERNAL , 0 );
290-     } else  {
291-         ucs_list_add_tail (& worker -> all_eps , & ucp_ep_ext_gen (ep )-> ep_list );
292-     }
293+     ucs_list_add_tail (& worker -> all_eps , & ucp_ep_ext_gen (ep )-> ep_list );
293294
295+ out :
294296    * ep_p  =  ep ;
295- 
296297    return  UCS_OK ;
297298
298299err_destroy_ep_base :
@@ -310,7 +311,7 @@ static void ucp_ep_delete(ucp_ep_h ep)
310311
311312    if  (!(ep -> flags  &  UCP_EP_FLAG_FAILED )) {
312313        ucp_ep_release_id (ep );
313-     } else  {
314+     } else  if  (!( ep -> flags   &   UCP_EP_FLAG_INTERNAL ))  {
314315        /* If FAILED flag set, EP ID was already released */ 
315316        ucs_assert (ucp_ep_ext_control (ep )-> local_ep_id  ==  UCP_EP_ID_INVALID );
316317    }
@@ -434,6 +435,10 @@ void ucp_worker_destroy_mem_type_endpoints(ucp_worker_h worker)
434435    ucs_memory_type_t  mem_type ;
435436    ucp_ep_h  ep ;
436437
438+     /* Destroy memtype UCP EPs after blocking async context, because cleanup 
439+      * lanes set FAILED flag (setting EP flags is expected to be guarded) */ 
440+     UCS_ASYNC_BLOCK (& worker -> async );
441+ 
437442    ucs_memory_type_for_each (mem_type ) {
438443        ep  =  worker -> mem_type_ep [mem_type ];
439444        if  (ep  ==  NULL ) {
@@ -443,10 +448,11 @@ void ucp_worker_destroy_mem_type_endpoints(ucp_worker_h worker)
443448        ucs_debug ("memtype ep %p: destroy" , ep );
444449        ucs_assert (ep -> flags  &  UCP_EP_FLAG_INTERNAL );
445450
446-         ucp_ep_cleanup_lanes (ep );
447-         ucp_ep_delete (ep );
451+         ucp_ep_destroy_internal (ep );
448452        worker -> mem_type_ep [mem_type ] =  NULL ;
449453    }
454+ 
455+     UCS_ASYNC_UNBLOCK (& worker -> async );
450456}
451457
452458ucs_status_t  ucp_ep_init_create_wireup (ucp_ep_h  ep , unsigned  ep_init_flags ,
@@ -825,19 +831,20 @@ void ucp_ep_destroy_internal(ucp_ep_h ep)
825831{
826832    ucs_debug ("ep %p: destroy" , ep );
827833    ucp_ep_cleanup_lanes (ep );
828-     if  (ep -> flags  &  UCP_EP_FLAG_INTERNAL ) {
829-         /* it's failed tmp ep of main ep */ 
830-         ucp_ep_destroy_base (ep );
831-     } else  {
832-         ucp_ep_delete (ep );
833-     }
834+     ucp_ep_delete (ep );
834835}
835836
836837static  void  ucp_ep_set_lanes_failed (ucp_ep_h  ep , uct_ep_h  * uct_eps )
837838{
838839    ucp_lane_index_t  lane ;
839840    uct_ep_h  uct_ep ;
840841
842+     if  (!(ep -> flags  &  (UCP_EP_FLAG_FAILED  | UCP_EP_FLAG_INTERNAL ))) {
843+         ucp_ep_release_id (ep );
844+     }
845+ 
846+     ucp_ep_update_flags (ep , UCP_EP_FLAG_FAILED , 0 );
847+ 
841848    for  (lane  =  0 ; lane  <  ucp_ep_num_lanes (ep ); ++ lane ) {
842849        uct_ep         =  ep -> uct_eps [lane ];
843850        uct_eps [lane ] =  uct_ep ;
@@ -1015,12 +1022,6 @@ void ucp_ep_discard_lanes(ucp_ep_h ep, ucs_status_t status)
10151022
10161023    ucs_debug ("ep %p: discarding lanes" , ep );
10171024
1018-     if  (!(ep -> flags  &  (UCP_EP_FLAG_FAILED  | UCP_EP_FLAG_INTERNAL ))) {
1019-         ucp_ep_release_id (ep );
1020-     }
1021- 
1022-     ucp_ep_update_flags (ep , UCP_EP_FLAG_FAILED , 0 );
1023- 
10241025    /* flush CANCEL mustn't be called for EPs without error handling support */ 
10251026    ucs_assert (ucp_ep_config (ep )-> key .err_mode  ==  UCP_ERR_HANDLING_MODE_PEER );
10261027    ucp_ep_set_lanes_failed (ep , uct_eps );
0 commit comments