[ 
https://issues.apache.org/jira/browse/DIRMINA-1172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17716912#comment-17716912
 ] 

Emmanuel Lécharny commented on DIRMINA-1172:
--------------------------------------------

Quick comment: I wonder if it's not the 'normal' behaviour. We use a Session 
recycler to avoid creating sessions again and again. We have a default recycler 
instance which fetch session based on their remote address, not considering the 
port. Here is the cocde:

 
{code:java}
    private IoSession newSessionWithoutLock(SocketAddress remoteAddress, 
SocketAddress localAddress) throws Exception {        
        DatagramChannel handle = boundHandles.get(localAddress);
        
        if (handle == null) {
            throw new IllegalArgumentException("Unknown local address: " + 
localAddress);
        }

        IoSession session;
        synchronized (sessionRecycler) {
            session = sessionRecycler.recycle(remoteAddress);
            if (session != null) {
                return session;
            }
    ... {code}
 

and:

 
{code:java}
public final class NioDatagramAcceptor extends AbstractIoAcceptor implements 
DatagramAcceptor, IoProcessor<NioSession> {
    /**
     * A session recycler that is used to retrieve an existing session, unless 
it's too old.
     **/
    private static final IoSessionRecycler DEFAULT_RECYCLER = new 
ExpiringSessionRecycler();
 {code}
 

with:

 
{code:java}
    /**
     * {@inheritDoc}
     */
    @Override    public IoSession recycle(SocketAddress remoteAddress) {
        return sessionMap.get(remoteAddress);
    }{code}
 

So I wonder if we are not in this exact use case, where the events are 
propagated to all the sessions, because we 'recycle' sessions that are already 
used.

That means we should use the remote address plus the port to identify sessions.

Note that the reason we recycle sessions is that with UDP the session is pretty 
much a temporary construction: it last for a given period of time then is 
deleted (we can't know when the 'session' is closed by the client, because of 
the connectionless nature of UDP).

I can modify the code for testing purpose, if you don't mind playing with it.

 

> Multiple DatagramAcceptors and the creation of a session object
> ---------------------------------------------------------------
>
>                 Key: DIRMINA-1172
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-1172
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1.5
>            Reporter: Alexander B
>            Priority: Major
>
> Hello,
> I am using two independently created NioDatagramAcceptors, which are created 
> by the following code :
> {code:java}
> AbstractIoService inputSource = new NioDatagramAcceptor();
> ((NioDatagramAcceptor) inputSource).getSessionConfig().setReuseAddress(true);
> DefaultIoFilterChainBuilder filterChainBuilderUDP = 
> ((NioDatagramAcceptor)inputSource).getFilterChain();
> filterChainBuilderUDP.addLast("logger", new LoggingFilter());
> ((NioDatagramAcceptor) 
> inputSource).getSessionConfig().setIdleTime(IdleStatus.READER_IDLE, 
> getIdleTimeout());
> ((NioDatagramAcceptor) inputSource).setHandler(this);
> try {
>       ((NioDatagramAcceptor)inputSource).bind(new InetSocketAddress(port));
> } catch (IOException e) {
>       log.error("Failed to connect {}", e);
> }
> {code}
> One Acceptor is listening on port 9800, the other one on 9801. If I now send 
> UDP packages (from a external application) to both ports (independently). It 
> seems, that both UDP port are "connected" to the same session.
> Information: The external app is sending:
> Message "TEST_1 <timestamp>" just to port 9800
> Message "TEST_2 <timestamp>" just to port 9801
> The overwritten method messageReceived will give the following output:
> {code:java}
> public void messageReceived(IoSession session, Object message) throws 
> Exception {
>       String msgStr = message.toString();
>       log.info("SessionId:" + session.getId() + " " + msgStr);
> }
> {code}
> 2023-04-19_11:47:35.035 [NioDatagramAcceptor-2] INFO - SessionId:1 TEST_1 
> 1681904855701
> 2023-04-19_11:47:35.035 [NioDatagramAcceptor-3] INFO - SessionId:1 TEST_2 
> 1681904855701
> So, both messages (for port 9800 and port 9801) are received by SessionId1. 
> If I do exactly the same with `NioSocketConnector`, I can see two different 
> sessions, such that both messages are handled independently:
> 2023-04-19_11:44:35.725 [NioProcessor-11] INFO - SessionId:1 TEST_1 
> 1681904875701
> 2023-04-19_11:44:37.754 [NioProcessor-15] INFO - SessionId:2 TEST_2 
> 1681904875701
> Is there anything I did not mention in the context of UDP/DatagramAcceptor? 
> Or is there any setting, such that DatagramAcceptors can create/handle their 
> own session objects?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to