Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

vmysql: sql error[3]: MySQL server has gone away

Well, I am in the mid­dle of mi­grat­ing a rather large mail server, us­ing qmail+vpop­mail+mysql+­couri­er-imap.

And just when it's start­ing in­to pro­duc­tion us­age, we find the er­ror in the ti­tle.

A lot.

Sad­ly, since that er­ror in­di­cates a failed MySQL query, it means you get stuff like ran­dom auth fail­ures. Which sucks a lot.

Googling gave a lot of hints. But noth­ing would fix it.

Un­til.... lucky strike.

So, I will put my so­lu­tion here for fu­ture googler­s.

If you see this:

vmysql: sql error[3]: MySQL server has gone away
vmysql: sql error[3]: MySQL server has gone away
vmysql: sql error[3]: MySQL server has gone away
vmysql: sql error[3]: MySQL server has gone away
vmysql: sql error[3]: MySQL server has gone away

Do the fol­low­ing:

  1. Check if you are ex­ceed­ing mysql's max_­­con­nec­­tions pa­ram­e­ter. The de­­fault is 100.

  2. Check if your cpu can take the load. (No, don't look at the load av­er­age. Look at the CPU us­age).

  3. Make re­al­­ly sure that vpop­­mail and couri­er-au­th­lib are built us­ing the ex­act mysql you have in­­stalled. No, it does­n't mat­ter if it's the same ver­­sion. Go, and re­build the things!

That fixed it for me.

On oth­er bizarre news about this server, I have low CPU us­age (95% idle), low IO (io­stat re­ports un­der 1M­B/sec, 40 tp­s), yet I have a load that can go up to 120.

Yet, in­ter­ac­tive re­sponse is fine.


A simple question

I was try­ing to do some­thing weird: take one of my PyQt prog­gies, and com­pile it in­to a stand­alone bi­na­ry us­ing Jython, koala/qt­ja­va and gjc.

Sad­ly, it does­n't work :-(

Has any­one ev­er got­ten a rather re­cent gjc and jython to work to­geth­er?

The best I can get is this:

[ralsina@monty jython]$ gcj -fjni /usr/lib/lib-org-*.so.* --classpath=/usr/java/j2sdk1.4.2_08/jre/lib/ --main=org.python.util.jython /usr/share/java/dom3-xerces-j2.jar /usr/share/java/ant.jar /usr/share/java/servlet.jar /usr/share/java/oro.jar /usr/share/java/jython.jar  -o jython
org/apache/html/dom/ error: cannot find file for class
org/apache/html/dom/ error: cannot find file for class org.w3c.dom.TypeInfo
org/apache/html/dom/ error: cannot find file for class org.w3c.dom.html.HTMLElement
org/apache/html/dom/ error: cannot find file for class org.w3c.dom.html.HTMLAnchorElement
org/apache/html/dom/HTMLAnchorElementImpl.class:0: confused by earlier errors, bailing out

This is us­ing gc­c-­java-3.4.3-22.1 and jython-2.2-0.a0.2jpp

I mean, this is com­plete­ly un­nec­es­sary, but it would be a nice hack :-)

A *real* programming challenge.

A long time ago, I wrote a piece about how I did­n't like kcal­c. It con­tained a very lame pyqt script show­ing a (IMHO) nicer cal­cu­la­tor. Strange­ly, that lead to two very cool im­ple­men­ta­tions of the con­cep­t!

One of them was writ­ten in Ruby, the oth­er one in C++. I think that has some po­ten­tial.

A few months lat­er, I wrote a spread­sheet based on the same con­cep­t. Al­so based on PyQt.

This Stupid­Sheet has some con­cep­tu­al prob­lem­s. Like, if you want to im­port Ex­cel sheet­s, you would have to re­write ba­sic in python, so it's not a prac­ti­cal pro­gram, but it is a rather nice ex­am­ple show­ing pro­gram­ming us­ing dy­nam­ic lan­guages.

In fac­t, I used it as such last week at Cafe­Con­f.

Now, here's the chal­lenge. If peo­ple that know how to write Ru­by or Ja­va apps us­ing Qt (or KDE, why not) could write a sim­i­lar ap­pli­ca­tion, we all could write a com­par­a­tive guide to Qt/KDE pro­gram­ming on dif­fer­ent lan­guages.

Since we would all be start­ing with a not-­too-­com­plex, but re­al­ly non-triv­ial ex­am­ple, and we would all do the same one, it should be pret­ty un­bi­ased.

In fac­t, if you think this ex­am­ple is bi­ased, please pro­pose an­oth­er one, and do this thing any­way.

You can find Stupid­Sheet here

It has some small bugs (try set­ting B1 to A1+1 with no val­ue in A1 ;-) but they are easy to fix.

We could re­move some fea­tures (like the weird past­ing stuff) to make the ex­am­ple more di­dac­tic.

I hope this gets some an­swers :-)

CafeConf 2005

Nue­va­mente este año voy a es­tar en Cafe­Conf . Es una char­la de 45 min­u­tos so­bre PyQt el 13 de oc­tubre al mediodía.

La idea: La gente se sor­prende cuan­do uno agar­ra KHTM­L, en­gan­cha un par de wid­gets y sale con un nave­g­ador we­b. Se de­be­ri­an sor­pren­der más de que uno puede par­tir de una re­c­eta de 20 líneas en una pági­na web y ter­mi­nar con una planil­la que fun­ciona ;-)

Por lo tan­to, voy a mostrar Stupid­Sheet co­mo un ejem­p­lo de que el de­sar­rol­lo de soft­ware con in­ter­face grá­fi­ca es mas facil de lo que la gente cree.

Co­mo siem­pre, si men­cionás es­ta pági­na, te ganás una cerveza. Máx­i­mo 2 cerveza­s, no muy bue­nas.

I will be at Cafe­Conf again this year. It's a 45-minute thing about PyQt in Oc­to­ber 13th, at noon.

My idea is: Peo­ple are amazed when you hook Khtml to a cou­ple of wid­gets and write a lame web brows­er. They should be more amazed that it is pos­si­ble to start with noth­ing more than a 20-­line recipe from a web­site and end with a func­tion­al spread­sheet ;-)

So, I will be show­ing Stupid­Sheet as an ex­am­ple of how writ­ing GUI soft­ware in Python is sim­pler than peo­ple think.

As usu­al, if you men­tion this page, you get a free beer, max­i­mum 2 beer­s, and not very good beer.

Authenticated Pages in CherryPy

Cher­ryPy is a cool, python­ic, sim­ple, quick, fun way to write web ap­pli­ca­tion­s.

I of­ten use Cher­ryPy to write cus­tom web ad­min tools for cus­tomer­s. Sup­pose you want to pro­vide them with a sim­ple way for pass­word man­age­men­t. Usu­al­ly I have the fol­low­ing re­quire­ments:

  • It must be sim­­ple ( not we­b­min )

  • It must not be a ter­mi­­nal ses­­sion (bye ssh :-( )

  • It must not be a graph­i­­cal ses­­sion (sad­­ly, that leaves out PyQt :-( )

  • It needs to do cus­­tom stuff: set the sam­­ba pass­­word at the same time, send a mail warn­ing about the next forced change, what­ev­er.

Some­day I may be able to use a sin­gle-app freeNX ses­sion, but right now that's a bit too much prob­lem for dif­fer­ent rea­son­s.

So, I wrote a Cher­ryPy page. Over time, I have be­come quite fond of it, and wrote a bunch of small tools around it. One of them was a way to lo­gin the us­er in­to the site us­ing the sys­tem's users and pass­word­s. Now I got to throw it away :-)

The new Cher­ryPy 2.1 has a mech­a­nism for im­ple­ment­ing pass­word-pro­tect­ed pages, called the Ses­sion au­then­ti­cate fil­ter which is sad­ly not doc­u­ment­ed yet any­where I can find.

So, here is my at­temp­t, so peo­ple googling it up can use it. Ex­cuse me:

cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter cher­rypy ses­sio­n­au­then­ti­cate­filter

That should do it :-)

What you need first is a func­tion that takes a user­name and pass­word, and re­turns None on suc­cess, or an er­ror mes­sage for the fail­ure.

For example, I can adapt something I wrote earlier using check­pass­word-­pam

def validPass(name,password):
                cmd='/usr/bin/checkpassword-pam -s xdm -- /bin/true 3<&0'
                print cmd,s
                if r==None: #Success
                        return None
        return "Login Incorrect"

Al­so, you may want a func­tion that re­turns the lo­gin screen. If you do, re­mem­ber the fol­low­ing:

  1. It must set the form ac­tion to doLo­gin

  2. The us­er field should be called lo­gin

  3. The pass­word field should be called pass­word

  4. You will take a fromPage ar­gu­ment that you should pass through, so the us­er will end on the page he wants.

  5. You will take a er­rorMsg ar­gu­ment which is prob­a­bly the re­sult of a failed pre­vi­ous lo­gin. Dis­play it red or some­thing like it. Un­less it's emp­ty, in which case it should not be vis­i­ble.

Here's mine.

def loginScreen(fromPage, login = '', errorMsg = ''):
<form method="post" action="doLogin">
<div align=center>
        <span class=errormsg>%s</span><p>
        <table >
                <input type="text" name="login" value="%s" size="40"/>
        <input type="password" name="password" size="40"/>
        <input type="hidden" name="fromPage" value="%s"/>
        <td colspan=2 align=right>
        <input type="submit" value="Login" />
""" % (errorMsg, login, fromPage)
return renderTemplate(file='logintemplate.html')

Al­though I am us­ing a tem­plate to dis­play it nice­ly and with the right style, it should be pret­ty ob­vi­ous how it work­s.

You could use the de­fault lo­gin screen pro­vid­ed by the fil­ter. While it work­s, it's just ug­ly.

Then you need to ap­ply the fil­ter to the set of your pass-pro­tect­ed pages. Sup­pose you want the whole site to be pro­tect­ed, ex­cept for your /stat­ic di­rec­to­ry, which con­tains the stylesheet, im­ages and such. Then you put this in your con­fig­u­ra­tion file:



Next thing is to hook the ses­sion au­then­ti­cate fil­ter to your cus­tom auth code. In your ap­p, do the fol­low­ing. It seems that you can't do this in the con­fig file, though, so do it in code.

            '/': {
                                    'sessionAuthenticateFilter.checkLoginAndPassword': validPass,

And that's it. Now your site is pass­word pro­tect­ed. You can even have dif­fer­ent au­then­ti­ca­tion schemes for dif­fer­ent pieces of the site, by re­set­ting the hooks for the fold­er you pre­fer to a dif­fer­ent func­tion.

Al­so, I think this is a good ex­am­ple of why I like Cher­ryPy. This mech­a­nism is both flex­i­ble, pow­er­ful and sim­ple.

Contents © 2000-2022 Roberto Alsina