Implementing Store and getting java.io.StreamCorruptedException

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing Store and getting java.io.StreamCorruptedException

Jonathan Yom-Tov
I implemented my own Store which uses Redis to persist sessions (I'm using
Jedis as the interface library). I copied most of the load()/save() code
from FileStore. When my Store loads the session from Redis I consistently
get java.io.StreamCorruptedException: Inconsistent vector internals. Any
ideas on why this might be happening?

Here's the relevant code:
@Override
public Session load(String sessionId) throws ClassNotFoundException,
IOException {
System.out.println("JEDIS load " + sessionId);
String key = getKey(sessionId);
byte[] bytes = jedis.get(key.getBytes(UTF8));
System.out.println("JEDIS loaded " + bytes.length + " bytes");

ClassLoader oldThreadContextCL =
manager.getContext().bind(Globals.IS_SECURITY_ENABLED, null);
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bis)) {
StandardSession session = (StandardSession) manager.createEmptySession();
session.readObjectData(ois);
session.setManager(manager);

return session;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
return null;
} finally {
manager.getContext().unbind(Globals.IS_SECURITY_ENABLED,
oldThreadContextCL);
}
}

@Override
public void save(Session session) throws IOException {
System.out.println("JEDIS save " + session.getId());
String key = getKey(session.getId());
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
((StandardSession)session).writeObjectData(oos);
jedis.set(key.getBytes(UTF8), bos.toByteArray());
}
}
Reply | Threaded
Open this post in threaded view
|

Re: Implementing Store and getting java.io.StreamCorruptedException

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jonathan,

On 5/20/20 10:55, Jonathan Yom-Tov wrote:
> I implemented my own Store which uses Redis to persist sessions
> (I'm using Jedis as the interface library). I copied most of the
> load()/save() code from FileStore. When my Store loads the session
> from Redis I consistently get java.io.StreamCorruptedException:
> Inconsistent vector internals. Any ideas on why this might be
> happening?

Does everything work if you don't have a java.util.Vector in your sessio
n?

Possibly relevant: https://bugs.openjdk.java.net/browse/JDK-8216331

- -chris

>
> Here's the relevant code: @Override public Session load(String
> sessionId) throws ClassNotFoundException, IOException {
> System.out.println("JEDIS load " + sessionId); String key =
> getKey(sessionId); byte[] bytes = jedis.get(key.getBytes(UTF8));
> System.out.println("JEDIS loaded " + bytes.length + " bytes");
>
> ClassLoader oldThreadContextCL =
> manager.getContext().bind(Globals.IS_SECURITY_ENABLED, null); try
> (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
> ObjectInputStream ois = new ObjectInputStream(bis)) {
> StandardSession session = (StandardSession)
> manager.createEmptySession(); session.readObjectData(ois);
> session.setManager(manager);
>
> return session; } catch (Exception e) {
> System.err.println(e.getMessage()); e.printStackTrace(); return
> null; } finally {
> manager.getContext().unbind(Globals.IS_SECURITY_ENABLED,
> oldThreadContextCL); } }
>
> @Override public void save(Session session) throws IOException {
> System.out.println("JEDIS save " + session.getId()); String key =
> getKey(session.getId()); try (ByteArrayOutputStream bos = new
> ByteArrayOutputStream(); ObjectOutputStream oos = new
> ObjectOutputStream(bos)) {
> ((StandardSession)session).writeObjectData(oos);
> jedis.set(key.getBytes(UTF8), bos.toByteArray()); } }
>
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl7H6Y0ACgkQHPApP6U8
pFinPxAAitgiD5+T/KfdmKdRuwgUjT+mZi94HaajY9gRmkcFYSvTp3Dp7f1fJIfz
nPb/TlzfzCnhqeJLMNcTGB5AH7UG/SrQRftBdb/sTcxW3M4+WNklhfwAw3OrjnQG
GbHVF8O38T6dfHhc7WonXY90Cs1qZ0c1jtsQUStPZHdvD7cee3vO69RYyxH8AB1D
dc6m5Yp15MdK3l18iCawotvNXqtSHEiWQtArKRh/xWtv/O+0H5EqanzWgKdc0tWf
e2UqDL7w+pMuD9gTP5yYtSfaYjXyJoT3Yf9yqfGlaKizvsceTFImU1e4/cj9x1fK
9sds6G0SPRVBcdT2yhzN/qLeXWlcpDh8+TImqtVL1lEJzVXQgol5aWzDJivyLv62
t5Xp+RB9YdA9cbY2OP5lDQI5sD6p7FP1TeZMdsd49ns4TkkTQBffTmX4jwlP0Mrh
zJPJg88u1lGsmJ/TRxLPHMgyEDU2VSduYMzcFYiLcYweYfYxlyFhIcZvGxj1+knq
dEe3CfYKG1IHBvhcR5maXV7cjUr5bf5dLOWbme+XT+Qd9i2Lnd1p9aVm/lGDieOi
C3L67vS+vQ7s1cly96vMMtDjnuPHyKsmBpyMMjGJV3WsYl5nuPxKzyywbKjWHa2l
m7ouCRI39pf3zUYbbWs52qEGg2uDjax+BDnvAkj6V+HI7mLdqsQ=
=p/9Q
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Implementing Store and getting java.io.StreamCorruptedException

Jonathan Yom-Tov
For posterity's sake: the issue was that I hadn't noticed that StoreBase
has the method getObjectInputStream which should be used instead of new
ObjectInputStream. So while the session was serialized correctly using
StandardSession's mechanism, it didn't deserialize correctly.

On Fri, May 22, 2020 at 6:02 PM Christopher Schultz <
[hidden email]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Jonathan,
>
> On 5/20/20 10:55, Jonathan Yom-Tov wrote:
> > I implemented my own Store which uses Redis to persist sessions
> > (I'm using Jedis as the interface library). I copied most of the
> > load()/save() code from FileStore. When my Store loads the session
> > from Redis I consistently get java.io.StreamCorruptedException:
> > Inconsistent vector internals. Any ideas on why this might be
> > happening?
>
> Does everything work if you don't have a java.util.Vector in your sessio
> n?
>
> Possibly relevant: https://bugs.openjdk.java.net/browse/JDK-8216331
>
> - -chris
>
> >
> > Here's the relevant code: @Override public Session load(String
> > sessionId) throws ClassNotFoundException, IOException {
> > System.out.println("JEDIS load " + sessionId); String key =
> > getKey(sessionId); byte[] bytes = jedis.get(key.getBytes(UTF8));
> > System.out.println("JEDIS loaded " + bytes.length + " bytes");
> >
> > ClassLoader oldThreadContextCL =
> > manager.getContext().bind(Globals.IS_SECURITY_ENABLED, null); try
> > (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
> > ObjectInputStream ois = new ObjectInputStream(bis)) {
> > StandardSession session = (StandardSession)
> > manager.createEmptySession(); session.readObjectData(ois);
> > session.setManager(manager);
> >
> > return session; } catch (Exception e) {
> > System.err.println(e.getMessage()); e.printStackTrace(); return
> > null; } finally {
> > manager.getContext().unbind(Globals.IS_SECURITY_ENABLED,
> > oldThreadContextCL); } }
> >
> > @Override public void save(Session session) throws IOException {
> > System.out.println("JEDIS save " + session.getId()); String key =
> > getKey(session.getId()); try (ByteArrayOutputStream bos = new
> > ByteArrayOutputStream(); ObjectOutputStream oos = new
> > ObjectOutputStream(bos)) {
> > ((StandardSession)session).writeObjectData(oos);
> > jedis.set(key.getBytes(UTF8), bos.toByteArray()); } }
> >
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl7H6Y0ACgkQHPApP6U8
> pFinPxAAitgiD5+T/KfdmKdRuwgUjT+mZi94HaajY9gRmkcFYSvTp3Dp7f1fJIfz
> nPb/TlzfzCnhqeJLMNcTGB5AH7UG/SrQRftBdb/sTcxW3M4+WNklhfwAw3OrjnQG
> GbHVF8O38T6dfHhc7WonXY90Cs1qZ0c1jtsQUStPZHdvD7cee3vO69RYyxH8AB1D
> dc6m5Yp15MdK3l18iCawotvNXqtSHEiWQtArKRh/xWtv/O+0H5EqanzWgKdc0tWf
> e2UqDL7w+pMuD9gTP5yYtSfaYjXyJoT3Yf9yqfGlaKizvsceTFImU1e4/cj9x1fK
> 9sds6G0SPRVBcdT2yhzN/qLeXWlcpDh8+TImqtVL1lEJzVXQgol5aWzDJivyLv62
> t5Xp+RB9YdA9cbY2OP5lDQI5sD6p7FP1TeZMdsd49ns4TkkTQBffTmX4jwlP0Mrh
> zJPJg88u1lGsmJ/TRxLPHMgyEDU2VSduYMzcFYiLcYweYfYxlyFhIcZvGxj1+knq
> dEe3CfYKG1IHBvhcR5maXV7cjUr5bf5dLOWbme+XT+Qd9i2Lnd1p9aVm/lGDieOi
> C3L67vS+vQ7s1cly96vMMtDjnuPHyKsmBpyMMjGJV3WsYl5nuPxKzyywbKjWHa2l
> m7ouCRI39pf3zUYbbWs52qEGg2uDjax+BDnvAkj6V+HI7mLdqsQ=
> =p/9Q
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
[image: SysAid Technologies]
<http://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo>
Jonathan Yom-Tov
Senior Architect
[hidden email]
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]
<https://www.sysaid.com/?utm_source=signature&utm_medium=email&utm_campaign=sysaid-logo-icon>
  [image: SysAid on Facebook] <https://www.facebook.com/SysAidIT>   [image:
SysAid on Twitter] <https://twitter.com/sysaid>   [image: SysAid on
Linked-in] <https://www.linkedin.com/company/sysaid-technologies-ltd>   [image:
SysAid on YouTube] <https://www.youtube.com/user/SysAidIT>   [image: SysAid
on Instagram] <https://www.instagram.com/sysaid_technologies/>
[image: Banner] <https://www.sysaid.com/sig-link>