Discussion:
[gambit-list] Some questions on tls contexts
Dimitris Vyzovitis
2018-03-26 07:38:00 UTC
Permalink
Marc,

Post refcount release bug, I've been looking more closely into the
implementation of tls contexts, and I have a couple of questions

1. The tls context contains internally allocated data, that is released
immediately with ___release_rc_tls_context in failure paths of
___os_make_tls_context.
However, I am not convinced it gets cleaned up when the tls context is
reclaimed by the gc.
Is there a finalizer for tls contexts or do we leak that internal
memory?

2. Is there a need to make a tls context per socket or can the tls context
be reused and shared among many (concurrent) sockets?
Currently I make a new context every time I make an https request, but
it would be very nice if a single context could be
reused.

-- vyzo
Dimitris Vyzovitis
2018-03-26 07:47:09 UTC
Permalink
Wrt question 2, experiments suggest that the tls context can be safely
reused.

-- vyzo
Post by Dimitris Vyzovitis
Marc,
Post refcount release bug, I've been looking more closely into the
implementation of tls contexts, and I have a couple of questions
1. The tls context contains internally allocated data, that is released
immediately with ___release_rc_tls_context in failure paths of
___os_make_tls_context.
However, I am not convinced it gets cleaned up when the tls context is
reclaimed by the gc.
Is there a finalizer for tls contexts or do we leak that internal
memory?
2. Is there a need to make a tls context per socket or can the tls context
be reused and shared among many (concurrent) sockets?
Currently I make a new context every time I make an https request, but
it would be very nice if a single context could be
reused.
-- vyzo
Marc Feeley
2018-03-26 12:34:44 UTC
Permalink
The ___release_rc_tls_context function is passed to ___NONNULLPOINTER_to_SCMOBJ to build the foreign obj (scm_ctx) that is returned to Scheme:

if ((scm_e =___NONNULLPOINTER_to_SCMOBJ
(___PSTATE,
___CAST(void*,c),
___FAL,
___release_rc_tls_context,
&scm_ctx,
___RETURN_POS)) != ___FIX(___NO_ERR))
{
___release_rc_tls_context (c);
return scm_e;
}

So the ___release_rc_tls_context function will be called when the foreign object is reclaimed by the GC.

Marc
Wrt question 2, experiments suggest that the tls context can be safely reused.
-- vyzo
Marc,
Post refcount release bug, I've been looking more closely into the implementation of tls contexts, and I have a couple of questions
1. The tls context contains internally allocated data, that is released immediately with ___release_rc_tls_context in failure paths of ___os_make_tls_context.
However, I am not convinced it gets cleaned up when the tls context is reclaimed by the gc.
Is there a finalizer for tls contexts or do we leak that internal memory?
2. Is there a need to make a tls context per socket or can the tls context be reused and shared among many (concurrent) sockets?
Currently I make a new context every time I make an https request, but it would be very nice if a single context could be
reused.
-- vyzo
Dimitris Vyzovitis
2018-03-26 12:36:16 UTC
Permalink
ok, thanks! I missed that nuance.

-- vyzo
Post by Marc Feeley
The ___release_rc_tls_context function is passed to
___NONNULLPOINTER_to_SCMOBJ to build the foreign obj (scm_ctx) that is
if ((scm_e =___NONNULLPOINTER_to_SCMOBJ
(___PSTATE,
___CAST(void*,c),
___FAL,
___release_rc_tls_context,
&scm_ctx,
___RETURN_POS)) != ___FIX(___NO_ERR))
{
___release_rc_tls_context (c);
return scm_e;
}
So the ___release_rc_tls_context function will be called when the foreign
object is reclaimed by the GC.
Marc
Post by Dimitris Vyzovitis
Wrt question 2, experiments suggest that the tls context can be safely
reused.
Post by Dimitris Vyzovitis
-- vyzo
Marc,
Post refcount release bug, I've been looking more closely into the
implementation of tls contexts, and I have a couple of questions
Post by Dimitris Vyzovitis
1. The tls context contains internally allocated data, that is released
immediately with ___release_rc_tls_context in failure paths of
___os_make_tls_context.
Post by Dimitris Vyzovitis
However, I am not convinced it gets cleaned up when the tls context
is reclaimed by the gc.
Post by Dimitris Vyzovitis
Is there a finalizer for tls contexts or do we leak that internal
memory?
Post by Dimitris Vyzovitis
2. Is there a need to make a tls context per socket or can the tls
context be reused and shared among many (concurrent) sockets?
Post by Dimitris Vyzovitis
Currently I make a new context every time I make an https request,
but it would be very nice if a single context could be
Post by Dimitris Vyzovitis
reused.
-- vyzo
Loading...