= The detach Statement

.Syntax
[source,unlang]
----
detach
----

The `detach` statement is used to separare a child request from a
parent request.  The `detach` statement can only be used inside of a
xref:unlang/subrequest.adoc[subrequest] section.

Once a child request is detached from the parent, the parent can
continue execution independently of the child.  However, once a child
request is detached from the parent request, the child can no longer
access any attributes in the parent.

.Example
[source,unlang]
----
subrequest Disconnect-Request {
    &User-Name := &parent.request.User-Name
    &NAS-IP-Address := &parent.request.NAS-IP-Address
    &NAS-Port := &parent.request.NAS-Port
    &Acct-Session-Id := &parent.request.Acct-Session-Id

    detach
    radius
}
----

== Child Lifetime

The lifetime of the child request is normally limited by the lifetime
of the parent request.  The default configuration has
`max_request_time = 30`, so child requests will be cancelled 30
seconds after the parent request was received.

When it is necessary to have the child request execute for longer, the
`Request-Lifetime` attribute can be set.  This attribute sets the
lifetime of the child request after it has been detached.  This
setting allows child requests to last longer than `max_request_time`
seconds from when the parent request was received.

The `Request-Lifetime` attribute sets the lifetime in seconds.  The
minimum lifetime is five (5) seconds.  The maximum lifetime is 3600
seconds.  Only integer seconds can be set.

.Example
[source,unlang]
----
subrequest Disconnect-Request {
    &User-Name := &parent.request.User-Name
    &NAS-IP-Address := &parent.request.NAS-IP-Address
    &NAS-Port := &parent.request.NAS-Port
    &Acct-Session-Id := &parent.request.Acct-Session-Id

    &control.Request-Lifetime := 60

    detach
    radius
}
----

// Copyright (C) 2021 Network RADIUS SAS.  Licenced under CC-by-NC 4.0.
// This documentation was developed by Network RADIUS SAS.
